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.

    Note

    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 a new XML file and save it with a .vstemplate extension in the same directory as your new item template.

  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. In Windows Explorer, select the files you want to include in your template, right-click, select Send To, and then click Compressed (zipped) Folder. The files that you selected are compressed into a .zip file.

  8. Copy the .zip file into the user item template location. In Windows Vista, the default directory is ..\Users\<username>\Documents\Visual Studio 2008\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="https://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

Tasks

How to: Create Item Templates

How to: Create Multi-file Item Templates

How to: Create Item Templates for Specific Project Types

How to: Add References to Templates

Concepts

How to: Locate and Organize Project and Item Templates

Reference

Visual Studio Template Schema Reference

Other Resources

Visual Studio Templates

Creating Project and Item Templates