Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Visual Studio 2015 appears to not honor the trailing whitespace. When I type header+TAB, the first using declaration appears on the same line as the last comment.

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?

like image 377
kbrimington Avatar asked Jun 13 '16 15:06

kbrimington


1 Answers

The common thing I'm seeing looking at the snippets that come with VS is most the code ends with $end$

Example from switch:

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

Place $end$ at the end of the trailing whitespace, like so:

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

$end$]]>
like image 105
Paul Swetz Avatar answered Nov 09 '22 23:11

Paul Swetz