How to: Manually Create Item Templates

The required items for creating a custom project item template are as follows:

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

  • The code file, for example, a Windows Form, Web form, class file, or resource file.

    Note

    You can also 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 put in a location that is 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 associated programming language.

To manually create an item template

  1. Create a project and project item.

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

  3. As appropriate, modify the code file to indicate where parameter replacement should occur. For more information about parameter replacement, see How to: Substitute Parameters in a Template.

  4. Create an XML file and save it by using a .vstemplate file name 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 the .vstemplate file and close it.

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

  8. Copy the .zip file and paste it in the user item template location. In Windows Vista, the default directory is ..\Users\<username>\Documents\Visual Studio 2010\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

Reference

Visual Studio Template Schema Reference

Concepts

How to: Locate and Organize Project and Item Templates

Other Resources

Visual Studio Templates

Creating Project and Item Templates