How to: Distribute Code Snippets

You can simply give your code snippets to your friends and have them install the snippets on their own computers by using the Code Snippet Manager. However, if you have several snippets to distribute, you can automate the process by including your snippet file in a Visual Studio installer (.vsi) file, which users can install into any edition of Visual Studio by using the Visual Studio Content Installer. .

Adding a .vscontent File

You need to include a manifest with the file extension .vscontent in your .vsi file. Here is the template you can use to create the file:

<VSContent xmlns="https://schemas.microsoft.com/developer/vscontent/2005">
    <Content>
        <FileName> </FileName>
        <DisplayName> </DisplayName>
        <Description> </Description>
        <FileContentType> </FileContentType>
        <ContentVersion>2.0</ContentVersion>
        <Attributes>
            <Attribute name="lang" value=""/>
        </Attributes>
    </Content>
</VSContent>

In this how-to we will use the code snippet created in Walkthrough: Creating a Code Snippet.

To Create a .vscontent File

  1. Create a new XML file and name it VBSnippet.vscontent.

  2. Add the template shown above.

  3. Fill in the fields:

    • FileName - VBCodeSnippet.snippet

    • Display Name - VB Code Snippet

    • Description - Visual Basic code snippets.

    • FileContentType - Code Snippet

    • Content Version - use 2.0 if the snippet should be used in Visual Studio 2008 or later, or 1.0 if it can be used in Visual Studio 2005.

    • Attribute - "vb"

    • Save the file.

Creating a .vsi File

  1. The .vsi file is really a .zip file with a different extension.

  2. Add the files VBSnippet.vscontent and VBCodeSnippet.snippet into a zip file named VBCodeSnippet.zip.

  3. Rename VBCodeSnippet.zip to VBCodeSnippet.vsi.

  4. This is all you need for a functional .vsi file. However, if you want to display publisher information for your code snippet in the Visual Studio Content Installer, you must sign the .vsi file. For more information, contact a Digital Certificate vendor.

Deploying the .vsi File

  1. Copy the .vsi file to any location on a computer that has Visual Studio installed.

  2. Double-click the .vsi file.

  3. The Visual Studio Content Installer window appears.

  4. If the Hello World Snippet file is not selected, select it and click Next.

  5. If the .vsi is not signed, you will see a warning dialog box named No Signature Found. To continue, click Yes.

  6. The following window shows installation locations for the snippet. Select My Code Snippets and click Next.

  7. The following window indicates whether or not the installation was successful. Click Finish, then Close.

  8. You should see the snippet installed in the Code Snippets Manager under Visual Basic My Code Snippets.

See Also

Other Resources

Code Snippets