Geeks With Blogs
Bryan Corazza for ( ; ; ) { BizTalk, Workflow, and .NET }

At its simpliest form a code snippet is nothing more than an xml file. 

Here's a sample of the schema:

<CodeSnippets
    xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
    <CodeSnippet Format="1.0.0">
        <Header>
            <Title>
                My Snippet
            </Title>
        </Header>
        <Snippet>
            <References>
                <Reference>
                    <Assembly>System.Windows.Forms.dll</Assembly>
                </Reference>
            </References>
            <Code Language="VB">
                <![CDATA[MessageBox.Show("Hello World")]]>
            </Code>
        </Snippet>
    </CodeSnippet>
</CodeSnippets>

In the Code element, the Language attribute takes the following values: VB, CSharp, VJSharp, and XML.

  • The SnippetType element takes the following text: SurroundsWith, Expansion, Refactoring.  These specify the way Visual Studio is going to insert the snippet.

So with this, all you need to do is create an xml file with the following schema and insert your own code and you're ready to go.  Make sure that the file has a .snippet extension on it and it is placed in the snippet directory that Visual Studio is pointing to.  By default its placed in the My Documents\Visual Studio 2005\Code Snippets\ folder, under its particular coding language.  Enjoy.

-B

Posted on Sunday, January 29, 2006 7:26 PM General .NET | Back to top


Comments on this post: How to create a simple code snippet for VS2005.

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Bryan Corazza | Powered by: GeeksWithBlogs.net