What's wrong with this code snippet?
Asked Answered
R

1

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>
Rumney answered 7/8, 2012 at 14:3 Comment(0)
R
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">
Redwine answered 7/8, 2012 at 14:8 Comment(4)
I fixed that, but I still get the same error message, so there must be more in there.Rumney
Adding the additional header tags does not fix the problem. I think those are optional.Rumney
Got it. It is the Code Language=C#. Changed to Code Language=CSharp and now it works.Redwine
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 .learn.microsoft.com/en-us/visualstudio/ide/…Whitener

© 2022 - 2024 — McMap. All rights reserved.