Code Snippet
-
2012년 8월 21일 화요일 오후 1:08
I have a problem with snippet.
I created Console Application and add XML file.
The XML file name is MySnippet.snippet ( ends with .snippet ).
Code for my snippet is
<CodeSnippet Format="1.0.0"
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>My snippet</Title>
<Author>Csharp_beginner</Author>
<Shortcut>hallo</Shortcut>
<Description>Hallo World snippet</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>name</ID>
<Default>value</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[
Console.WriteLine("Hallo World !");
Console.ReadLine();
]]>
</Code>
</Snippet>
</CodeSnippet>
Nothing special! :)
I imported the .snippet file into Visual Studio with Code Snippets Manager.
The default location for my snippet is C:\Users\<UserName>\Documents\Visual Studio 2010\Code Snippets\.
When I type the name of the snippet I see it but when I select my snippet and press enter I do not get code.
Appears Hallo (Hallo is shortcut).
When I press tab,tab appears
[CDATA[ Console.WriteLine("Hallo World !");
Console.ReadLine();]]
with many errors.
How to solve this problem?MSDN response to a question :)
모든 응답
-
2012년 8월 21일 화요일 오후 2:02중재자
The snippet you posted isn't a valid snippet file. The root element is CodeSnippets with one or more CodeSnippet elements under it. Here's a valid version:
<?xml version="1.0" encoding="utf-8" ?><CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Test</Title>
<Shortcut>Test</Shortcut>
<Description>Code snippet for destructor</Description>
<Author>Microsoft Corporation</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
</Header>
<Snippet>
<Declarations>
<Literal Editable="false">
<ID>classname</ID>
<ToolTip>Class name</ToolTip>
<Default>ClassNamePlaceholder</Default>
<Function>ClassName()</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[
Console.WriteLine("Hallo World !");
Console.ReadLine();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>Michael Taylor - 8/21/2012
http://msmvps.com/blosg/p3net
- 답변으로 제안됨 JohnGrove 2012년 8월 21일 화요일 오후 2:18
-
2012년 8월 21일 화요일 오후 2:19
The snippet you posted isn't a valid snippet file.
It works fine here as it is. Apparently, VS allows forgetting the root element if you have only one CodeSnippet in the file.
-
2012년 8월 21일 화요일 오후 2:29
-
2012년 8월 21일 화요일 오후 2:31
Louis.fr thanks for your reply, I corrected the mistake and now everything is OK.MSDN response to a question :)
- 답변으로 표시됨 Csharp_beginner 2012년 8월 21일 화요일 오후 2:34
-
2012년 8월 22일 수요일 오전 2:06중재자
Hi Csharp_beginner ,
Would you like to share the solution with us ? This will be helpful for other developers in the forum who have interests in this problem .Thanks .
Regards ,
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us

