有段时间以来,我一直在使用自定义的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>
重要的一点是,需要注意CDATA块末尾有两个换行符。在Visual Studio 2015之前的版本中,我可以将光标放到文件开头,在第一个using声明之前,键入“header+TAB”,然后我的标题会出现一个额外的空行,位于最后一个注释和第一个using声明之间。
但是,似乎Visual Studio 2015不支持尾随空格。当我键入“header+TAB”时,第一个using声明出现在最后一个注释的同一行上。
这是一个错误吗?还是有方法可以配置我的代码片段,使得Visual Studio 2015支持尾随空格呢?
\n
注入到我的源文件中。同样,在CDATA块之外添加

(XML中的\r\n
等效)也无法解决此问题。 - kbrimington
- Paul Swetz{ $cases$ }$end$]]> </Code>