Export (0) Print
Expand All

How to: Publish Code Snippets 

To get a code snippet to appear in the code editor, it must be placed on a user's computer and imported with the Code Snippet Manager. To make this process easier, you can place your snippet file inside of a Visual Studio Installer (.vsi) file and use the Visual Studio Content Installer to place the file in the correct location. The .vsi file can then be easily shared with other developers throughout the community.

.VSI Files

Visual Studio Installer (.vsi) files are used to exchange Visual Studio content in the developer community. A .vsi file is a renamed .zip file that contains:

The Visual Studio Content Installer uses .vsi files to install shared content to the proper location. For more information on installing .vsi files, see How to: Install Community Components.

You must set specific values and attributes in the .vscontent file for the Visual Studio Content Installer to know how and where to install the code snippet. In the .vscontent file for a code snippet, you must:

  • Set the FileContentType element value to Code Snippet.

  • Add an Attribute element with 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 on the .vscontent file schema, see How to: Package Community Components to Use the Visual Studio Content Installer.

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

  3. Rename the 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.

Example

The following example shows a .vscontent file for a .vsi that contains a code snippet. The following files would be included in the .vsi file for this content.

  • A .vscontent file with 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>1.0</ContentVersion>
        <Attributes>
            <Attribute name="lang" value="vb"/>
        </Attributes>
    </Content>
</VSContent>

See Also

Community Additions

ADD
Show:
© 2014 Microsoft