Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

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 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: 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, jsharp, vb, 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 Community 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.

    NoteNote:

    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 can be used by either Visual Studio or Visual Studio 2008, use a value of 1.0. If a code snippet is specific to Visual Studio 2008, use 2.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="http://schemas.microsoft.com/developer/vscontent/2005">
    <Content>
        <FileName>MyCodeSnippet.snippet</FileName>
        <DisplayName>Sample Code Snippet</DisplayName>
        <Description>A code snippet created for this example</Description>
        <FileContentType>Code Snippet</FileContentType>
        <ContentVersion>2.0</ContentVersion>
        <Attributes>
            <Attribute name="lang" value="vb"/>
        </Attributes>
    </Content>
</VSContent>
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft