在VS2010中创建自定义的代码段
本文基于Visual Studio 2010 RC版本
1. 在项目中新增一个xml文件为carysn.snippet,然后插入代码段,如下图:
2. 完成后会自动插入代码段模板,我们将模板中相关信息修改后如下:
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>CarySNTest</Title>
<Author>Cary</Author>
<Shortcut>CaryShortcut</Shortcut>
<Description>It is a test snippet</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>Author</ID>
<Default>Cary</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
/*--------------------------
Author:$Author$
Date:2010-02-22
--------------------------*/
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
]]>
</Code>
</Snippet>
</CodeSnippet>
3. 打开代码段管理器,如下图:
4.导入我们创建好的代码段,如下图:
5.然后我们就可以在程序中使用了,如下图:
本文转自生鱼片博客园博客,原文链接:http://www.cnblogs.com/carysun/archive/2010/02/22/vs2010-codesnippet.html,如需转载请自行联系原作者