简体   繁体   English

Visual Studio 2015 Code Snippet,具有重要的尾随空格

[英]Visual Studio 2015 Code Snippet with significant trailing whitespace

For some time I have had a custom Visual Studio code snippet to assist in injecting a copyright header in my C# source files. 有一段时间我有一个自定义的Visual Studio代码片段来帮助在我的C#源文件中注入版权标题。 It looks something like this: 它看起来像这样:

<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>

The important thing to note for this question is the two trailing endlines at the end of the CDATA block. 这个问题需要注意的重要事项是CDATA块末尾的两个尾随终端线。 In editions of Visual Studio prior to 2015, I could place my cursor at the beginning of a file, right before the first using declaration, type header+TAB , and my header would appear with an extra empty line in between the last comment and the first using declaration. 在2015年之前的Visual Studio版本中,我可以将光标放在文件的开头,就在第一个使用声明之前,输入header+TAB ,我的标题会在最后一个注释和最后一个注释之间出现一个额外的空行。首先使用声明。

Visual Studio 2015 appears to not honor the trailing whitespace. Visual Studio 2015似乎不尊重尾随空格。 When I type header+TAB , the first using declaration appears on the same line as the last comment. 当我输入header+TAB ,第一个using声明出现在与最后一个注释相同的行上。

Am I looking at a bug, or is there a way to configure my code snippet so that Visual Studio 2015 will honor the trailing whitespace? 我是在查看错误,还是有办法配置我的代码片段以便Visual Studio 2015能够支持尾随空格?

The common thing I'm seeing looking at the snippets that come with VS is most the code ends with $end$ 我看到的常见问题是看看VS附带的片段,大多数代码以$end$

Example from switch: 开关示例:

<Code Language="csharp"><![CDATA[switch ($expression$) { $cases$ }*$end$*]]> </Code> 

Place $end$ at the end of the trailing whitespace, like so: $end$放在尾随空格的末尾,如下所示:

<![CDATA[// -----------------------------------------------------------------------
// <copyright file="$FileName$.cs" company="Company Name">
// Copyright © 2011-2016 by Company Name. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

$end$]]>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM