片段在 VS2015 中插入额外的换行符

Snippet inserts extra newline in VS2015

我制作了一个用于 Visual Studio 的自定义片段。在 VS2013 中,它按预期工作,但自从在 VS2015(社区版)中使用它后,它一直在代码前插入一个额外的换行符(就在我第二次按 tab/enter 时)。

这似乎只是自定义代码段的问题(内置代码段工作正常)。任何人都知道是什么原因造成的?这很烦人。

附带说明一下,只有当我在空代码行上激活代码段时才会发生这种情况。如果我在现有代码之后执行此操作,则不会插入换行符。不幸的是,该片段是一个声明,所以这没有多大帮助。

这是几乎完全从 VS 示例中复制的片段:

<?xml version="1.0" encoding="utf-8" ?> 
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/CodeSnippet">
<CodeSnippet Format="1.0.0">

    <!-- The header contains information describing the snippet. -->
    <Header>

      <!-- The Title of the snippet, this will be shown in the snippets manager. -->
      <Title>Insert Field Add</Title>

      <!-- The description of the snippet. -->
      <Description>Inserts a basic field add for a DataObject</Description>

      <!-- The author of the snippet. -->
      <Author>Thomas Price</Author>

      <!-- The set of characters that must be keyed in to insert the snippet. -->
      <Shortcut>fadd</Shortcut>

      <!-- The set of snippet types we're dealing with - either Expansion or -->
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>          

    </Header>

    <!-- Now we have the snippet itself. -->
    <Snippet>
        <!-- Create any declarations that we use in the snippet. -->
        <Declarations>
          <Literal>
            <ID>FieldName</ID>
            <ToolTip>Enter the field name</ToolTip>
            <Default>field</Default>
          </Literal>
        </Declarations>

        <!-- Sepecify the code language and the actual snippet content. -->
        <Code Language="CSharp" Kind="any">
            <![CDATA[$FieldName$ = fields.add($FieldName$, "$FieldName$");]]>
        </Code>
    </Snippet>
</CodeSnippet>

您可以通过将 $end$ 放在代码段文本中的某处来防止前面的换行符。示例:

<![CDATA[$FieldName$ = fields.add($FieldName$, "$FieldName$");$end$]]>