How to: Publish Code Snippets

For a code snippet to appear in the code editor on a user's computer, it must be installed on the computer and imported into Visual Studio by using the Code Snippet Manager. To make this process easier, you can put your snippet file in a Visual Studio Installer (.vsi) file, which a user can put in the correct location by using the Visual Studio Content Installer. The .vsi file can then be easily shared with other developers throughout the community.

.VSI Files

.Vsi files are used to exchange Visual Studio content in the developer community. A .vsi file is just a .zip file, but it must be renamed by using a .vsi file name extension so that the Visual Studio Content Installer will know how to handle it. .Vsi files contain the following:

The Visual Studio Content Installer uses .vsi files to install shared content to the correct location. For more information about how to install .vsi files, see How to: Find and Install Community Components.

You must set specific values and attributes in the .vscontent file so that the Visual Studio Content Installer will know how and where to install the content files. For example, in the .vscontent file for a code snippet, you must do the following:

  • Set the FileContentType element value to Code Snippet.

  • Add an Attribute element that has the following attribute:

    • lang: Specifies the language of the code snippet, either csharp, vb, SQL, JScript, HTML, or xml.

To create a code snippet .vsi file

  1. Create a valid .vscontent file for the content. For more information about the .vscontent file schema, see How to: Package Components to Use the Visual Studio Content Installer.

  2. Select the files you want to include in the .vsi file (including the .vscontent file), right-click the selection, click Send To, and then click Compressed (zipped) Folder. The selected files are compressed into a single .zip file.

  3. Rename the file name extension of the .zip file to .vsi.


    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.


The following example shows a .vscontent file for a .vsi file that contains a code snippet. The example uses a ContentVersion value of 2.0. If a code snippet is specific to Visual Studio 2008 or later, use 2.0. If it can be also used by Visual Studio 2005, use a value of 1.0. The following files would be included in this .vsi file:

  • A .vscontent file that has the code from this example.

  • The code snippet MyCodeSnippet.snippet.

<VSContent xmlns="">
        <DisplayName>Sample Code Snippet</DisplayName>
        <Description>A code snippet created for this example</Description>
        <FileContentType>Code Snippet</FileContentType>
            <Attribute name="lang" value="vb"/>

See Also


How to: Package Components to Use the Visual Studio Content Installer


Creating and Using IntelliSense Code Snippets