kbr*_*ton 7 c# code-snippets visual-studio-2015
有一段时间我有一个自定义的Visual Studio代码片段来帮助在我的C#源文件中注入版权标题.它看起来像这样:
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>File Header</Title>
<Author>Me</Author>
<Shortcut>header</Shortcut>
<Description>Inserts a standard copyright header.</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>FileName</ID>
<ToolTip>The name of the C# code file.</ToolTip>
<Default>FileName</Default>
</Literal>
</Declarations>
<Code Language="CSharp"><![CDATA[// -----------------------------------------------------------------------
// <copyright file="$FileName$.cs" company="Company Name">
// Copyright © 2011-2016 by Company Name. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
]]></Code>
</Snippet>
</CodeSnippet>
Run Code Online (Sandbox Code Playgroud)
这个问题需要注意的重要事项是CDATA块末尾的两个尾随终端线.在2015年之前的Visual Studio版本中,我可以将光标放在文件的开头,就在第一个使用声明,类型之前header+TAB,我的标题会出现在最后一个注释和第一个使用声明之间的额外空行.
Visual Studio 2015似乎不尊重尾随空格.当我输入时header+TAB,第一个使用声明出现在与最后一个注释相同的行上.
我是在查看错误,还是有办法配置我的代码片段以便Visual Studio 2015能够支持尾随空格?
我看到的常见问题是看看VS附带的片段,大多数代码都以此结束 $end$
开关示例:
<Code Language="csharp"><![CDATA[switch ($expression$) { $cases$ }*$end$*]]> </Code>
Run Code Online (Sandbox Code Playgroud)
将$end$在后的空白,像这样的结尾:
<![CDATA[// -----------------------------------------------------------------------
// <copyright file="$FileName$.cs" company="Company Name">
// Copyright © 2011-2016 by Company Name. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
$end$]]>
Run Code Online (Sandbox Code Playgroud)