Creating Custom Project and Item Templates

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2019. Download it here

The Visual Studio SDK includes project templates that create a custom project template and a custom item template. These templates include some common parameter substitutions, and build as zip files. They are not automatically deployed, and they are not available in the experimental instance. Copy the zip file to the location you

The template creation templates let you include templates in larger extensions. Including templates in extensions lets you implement version control on the source files and build a group of template projects into one VSIX package.

For basic template creation scenarios, you should use the Export Template wizard, which outputs to a compressed file. For more information about basic template creation, see Creating Project and Item Templates.

Starting in Visual Studio 2017, scanning for custom project and item templates is no longer performed. Instead, the extension must provide template manifest files that describe the install location of these templates. You can use the Preview 2 installation to update your VSIX extensions. If you deploy your extension using an MSI, you must generate the template manifest files by hand. For more information, see Upgrade Custom Project and Item Templates for Visual Studio 2017. The template manifest schema is documented in Visual Studio Template Manifest Schema Reference.

Create a Project Template

  1. Create a Project Template project. You can find the project template in the New Project dialog, in the Visual Basic or Visual C# Extensibility folder.

    The template generates a class file, an icon, a .vstemplate file, an editable project file named ProjectTemplate.vbproj or ProjectTemplate.csproj, and some files that are typically generated by other project types, such a resources.resx file, an AssemblyInfo file, and a .settings file. Each code file contains common parameter substitutions where appropriate.

  2. Add and remove items from the project as required for your project. Do not remove the editable project file, the AssemblyInfo file, or the .vstemplate file.

  3. Update the .vstemplate file to reflect any additions and deletions. The Project element must contain a ProjectItem element for each file to be included in the template.

  4. Modify your code files and other user-facing content, and add appropriate parameter substitutions.

  5. Modify the generated content as required.

  6. Build the project.

    Visual Studio creates a .zip file that contains your template. It is not deployed, and it is not available in the experimental instance.

Create an Item Template

  1. Create an Item Template project.

    The template generates a class file, an icon, a .vstemplate file, and an AssemblyInfo file. The class file contains some common parameter substitutions.

  2. Add and remove items from the project as required for your project.

  3. Update the .vstemplate file to reflect any additions and deletions. The Project element must contain a ProjectItem element for each file to be included in the template.

  4. Modify your code files and other user-facing content, and add appropriate parameter substitutions.

  5. Modify generated content as required.

  6. Build the project.

    Visual Studio creates a compressed file that contains your template. It is not deployed, and it is not available in the experimental instance.

Deploy the project or item template

  1. Create a VSIX project. For more information, see VSIX Project Template.

  2. Set the VSIX project as the startup project. In the Solution Explorer, select the VSIX project node, right-click, and select Set as Startup Project.

  3. Set the project template project as an asset of the VSIX project. Open the .vsixmanifest file. Go to the Assets tab and click New.

    1. Set the Type field to Microsoft.VisualStudio.ProjectTemplate or Microsoft.VisualStudio.ItemTemplate.

    2. For source, select the A project in current solution option, and then select the project that contains your template.

  4. Build the solution, and press F5. The experimental instance appears.

  5. For a project template project, you should see your project template listed in the New Project dialog (File / New / Project), in the Visual C# or Visual Basic node. For an item template project, you should see your item template listed in the Add New Item dialog (in the Solution Explorer, select the project node and click Add / New Item).

See also