Share via


How to: Locate and Organize Project and Item Templates

Template files must be placed in a location that Visual Studio recognizes in order for the templates to appear in the New Project and Add New Item dialog boxes. You can create custom subcategories for templates so that these subcategories appear in the user interface.

Locating Templates

Visual Studio searches two locations for project and item templates by default. If a compressed file that includes a .vstemplate file exists in these locations, a template will appear in the New Project or Add New Item dialog boxes as appropriate.

Installed Templates

By default, templates installed with the product are located at:

  • <VisualStudioInstallDir>\Common7\IDE\ItemTemplates\Language\Locale\

  • <VisualStudioInstallDir>\Common7\IDE\ProjectTemplates\Language\Locale\

For example, the following directory contains all of the Visual Studio project templates for English:

C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\VisualBasic\1033\

Custom Templates

By default, custom templates are located at:

  • My Documents\Visual Studio 2008\Templates\ProjectTemplates\Language\

  • My Documents\Visual Studio 2008\Templates\ItemTemplates\Language\

For example, the following directory contains custom Visual C# project templates:

C:\Documents and Settings\UserName\My Documents\Visual Studio 2008\ProjectTemplates\Visual C#\

Custom templates do not include a subdirectory for localized templates. You can change the default directory for custom templates in the Options dialog box. For more information, see General, Projects and Solutions, Options Dialog Box.

Organizing Templates

The categories in the New Project and Add New Item dialog boxes reflect the directory structures that exist in the installed and custom template locations. You can modify these directory structures to organize your templates in a way that makes sense to you.

Note

You cannot create a new category at the programming language level. New categories can only be created within each language.

If the directory structures for installed and custom templates for a particular language do not have the same structure (that is, there are directories under one folder that do not exist under the other) the set of categories that appear in the New Project dialog will be the merger of all categories.

Organizing Installed Templates

You can organize installed templates by creating subdirectories within the programming language folder. These subdirectories appear as virtual folders in the New Project and Add New Item dialog boxes within each language.

To create new installed project template categories

  1. Create a new folder in the language folder of the installed template directory. For example, to create an Office category for Visual Studio project templates you would create the following directory:

    <VisualStudioInstallDir>\Common7\IDE\ProjectTemplates\VisualBasic\Office

  2. Place all the templates for this category in the new folder.

  3. Close all instances of Visual Studio.

  4. On the Start menu, click Run, type "cmd", and click OK.

  5. At the command prompt, navigate to the directory that contains devenv.exe, and type "devenv /setup".

  6. Run Visual Studio.

  7. On the File menu, click New, and then click Project.

  8. Verify that the Office category appears under Visual Basic in the Project types pane in the New Project dialog box.

Similarly, you can group a subset of the project item templates into a custom folder.

To create new installed item template categories

  1. Create a new folder in the language folder of the installed template directory. For example, to create a Web category for Visual C# item templates you would create the following directory:

    <VisualStudioInstallDir>\Common7\IDE\ItemTemplates\CSharp\Web\

  2. Place all templates for this category in the new folder.

  3. Close all instances of Visual Studio.

  4. On the Start menu, click Run, type "cmd", and click OK.

  5. At the command prompt, navigate to the directory that contains devenv.exe, and type "devenv /setup".

  6. Run Visual Studio.

  7. Create a new project or open an existing project.

  8. On the Project menu, click Add New Item.

  9. Verify that the Web category appears in the Project types pane in the Add New Item dialog box.

Organizing Custom Templates

Custom templates can be organized into their own categories by adding new folders in the custom template location. The New Project dialog box reflects any changes you make to your template categories.

To create new custom project template categories

  1. Create a new folder in the language folder in the custom project template directory. For example, to create a HelloWorld category for Visual C# templates you would create the following directory:

    My Documents\Visual Studio 2008\Templates\ProjectTemplates\CSharp\HelloWorld\

  2. Place all the templates for this category in the new folder.

  3. On the File menu, click New, and then click Project.

  4. Verify that the HelloWorld category appears under Visual C# in the Project types pane in the New Project dialog box.

Similarly, you can group a subset of the custom item templates into a custom folder.

To create new custom item template categories

  1. Create a new folder in the language folder in the custom item template directory. For example, to create a HelloWorld category for Visual C# templates you would create the following directory:

    My Documents\Visual Studio 2008\Templates\ItemTemplates\CSharp\HelloWorld\

  2. Place all the templates for this category in the new folder.

  3. Create a new project or open an existing project.

  4. On the Project menu, click Add New Item.

  5. Verify that the HelloWorld category appears in the Project types pane in the Add New Item dialog box.

Displaying Templates in Parent Categories

You can allow templates in subcategories to be displayed in their parent categories by using the NumberOfParentCategoriesToRollUp element in the .vstemplate file. This procedure is identical for both project and item templates.

To display templates in parent categories

  1. Locate the .zip file that contains the template.

  2. Extract the .zip file.

  3. Open the .vstemplate file in Visual Studio.

  4. In the TemplateData element, add a NumberOfParentCategoriesToRollUp element. For example, the following code makes the template visible in the parent category, but no higher:

    <TemplateData>
        ...
        <NumberOfParentCategoriesToRollUp>
            1
        </NumberOfParentCategoriesToRollUp>
        ...
    </TemplateData>
    
  5. Save and close the .vstemplate file.

  6. 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.

  7. Delete the extracted template files and the old template .zip file.

  8. Place the new .zip file in the same directory as the deleted .zip file.

See Also

Reference

Visual Studio Template Schema Reference

NumberOfParentCategoriesToRollUp (Visual Studio Templates)

Other Resources

Customizing Project and Item Templates

Visual Studio Templates

Creating Project and Item Templates