This documentation is archived and is not being maintained.

How to: Manually Create Item Templates 

The process for creating a custom item template is fairly simple. The required items for a project item template are as follows:

  • The metadata file (*.vstemplate) that Visual Studio uses to define how to display the project item in the development environment and, if you have specified the appropriate properties, to customize how the project item is created.

  • The code file, such as a Windows form, Web form, class file, or resource file.

    NoteNote

    It is also possible to create a multi-file item template. For more information, see How to: Create Multi-file Item Templates.

These two files are compressed into a .zip file. The .zip file must be placed in a location recognized by Visual Studio for custom project item templates. Custom project item templates appear in the Add New Item dialog box in the My Templates section for the appropriate programming language.

To manually create an item template

  1. Create a project and project item.

  2. Edit the project item until it is ready to be saved as a template.

  3. As appropriate, edit the code file to indicate where parameter replacement should take place. For more information on parameter replacement, see How to: Substitute Parameters in a Template.

  4. Create an XML file and save it with a .vstemplate extension in the same directory as your item.

  5. Author the .vstemplate XML file to provide item template metadata. For more information, see the example in the following section.

  6. Save and close the .vstemplate file.

  7. Select the files included in your template, right-click, select Send To, and click Compressed (zipped) Folder. The files that you selected are compressed into a .zip file.

  8. Place the .zip file in the user item template location. By default, the directory is \My Documents\Visual Studio 2005\Templates\ItemTemplates\. For more information, see How to: Locate and Organize Project and Item Templates.

Example

The following example shows a basic item .vstemplate file. This item template contains the metadata for a custom Visual C# class template, MyClass.cs.

<VSTemplate Type="Item" Version="2.0.0"
    xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
    <TemplateData>
        <Name>MyClass</Name>
        <Description>My custom C# class.</Description>
        <Icon>Icon.ico</Icon>
        <ProjectType>CSharp</ProjectType>
        <DefaultName>MyClass</DefaultName>
    </TemplateData>
    <TemplateContent>
        <ProjectItem>MyClass.cs</ProjectItem>
    </TemplateContent>
</VSTemplate>

See Also

Show: