18

I tried to import this into the Code Snippets Manager and got the error "The snippet files chosen were not valid." Since this is my first snippet, and the error message doesn't deign to point out why the snippet is not valid, I am at a loss.

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>EDI Property</Title>
      <Shortcut>edi</Shortcut>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>required</ID>
          <ToolTip>required</ToolTip>
          <Default>[Required]
          </Default>
        </Literal>
        <Literal>
          <ID>min</ID>
          <ToolTip>min</ToolTip>
          <Default>1</Default>
        </Literal>
        <Literal>
          <ID>max</ID>
          <ToolTip>max</ToolTip>
          <Default>10</Default>
        </Literal>
        <Literal>
          <ID>position</ID>
          <ToolTip>position</ToolTip>
          <Default>1</Default>
        </Literal>
        <Literal>
          <ID>type</ID>
          <ToolTip>type</ToolTip>
          <Default>string</Default>
        </Literal>
        <Literal>
          <ID>name</ID>
          <ToolTip>name</ToolTip>
          <Default>Property</Default>
        </Literal>
      </Declarations>
      <Code Language="C#">
        <![CDATA[
        $required$[MinLength($min$)]
        [MaxLength($max$)]
        [ElementPosition($position$)]
        public $type$ $name$ { get; set; }
        ]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
Thom Smith
  • 13,916
  • 6
  • 45
  • 91

1 Answers1

29

Your first line is wrong

<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet"></CodeSnippets>

remove the ending </CodeSnippets>

I'm checking against an example created by SnippetDesigner (recommended)
Looks like some tags are missing

  <Title>MySnippet</Title>
  <Author>Steve</Author>
  <Description>
  </Description>
  <HelpUrl>
  </HelpUrl>

also, I haven't find an example where

<Code Language="C#">

but

<Code Language="CSharp">
Steve
  • 213,761
  • 22
  • 232
  • 286
  • I fixed that, but I still get the same error message, so there must be more in there. – Thom Smith Aug 07 '12 at 14:11
  • Adding the additional header tags does not fix the problem. I think those are optional. – Thom Smith Aug 07 '12 at 14:18
  • 8
    Got it. It is the `Code Language=C#`. Changed to `Code Language=CSharp` and now it works. – Steve Aug 07 '12 at 14:25
  • after this any one have error .Then create xml file in visual studio and add your snippet on that then you can see any error on that syntax .I solved like this .https://learn.microsoft.com/en-us/visualstudio/ide/walkthrough-creating-a-code-snippet?view=vs-2015&redirectedfrom=MSDN – lava Apr 10 '20 at 12:54