Deploying Visual Studio templates

Sharing Visual Studio templates with colleagues can be time consuming depending on the chosen distribution mechanism. This article shows how to package and deploy templates to a shared location, greatly simplifying the process of company wide template maintenance. Examples are based on Visual Studio 2010 and Windows 7.


To make use of Visual Studio item and project templates they need to be placed in an appropriate subfolder of the Visual Studio template directory, located in “[personal folder]\Documents\Visual Studio 2010\Templates” by default (e.g. “C:\Users\Uli\Documents\Visual Studio 2010\Templates”). Changing this location to a central storage must be done on each computer in question and consists of changing two registry entries.

The default set of project and item templates that are installed with Visual Studio are stored as ZIP-archives. Custom templates can be stored as ZIP-archives as well, but don’t have to — they can also simply be stored as unpacked files in an appropriate subfolder of the Visual Studio template directory (e.g. “[…]\Visual Studio 2010\Templates\ProjectTemplates\Visual C#\MyCompany\SitecoreProjectTemplate\”). Personally I find it easier to maintain non-zipped templates, but YMMV.


Template packaging

Creating a zipped template package consists of adding all relevant files to an archive following these rules:

  • The archive must contain a template definition (.vstemplate-file).
  • The template definition must be located directly in the archive root. Both images below show the root of a ZIP-archive intended to be used as a Visual Studio template. In the first image the .vstemplate-file has incorrectly been placed within a subfolder of the archive.
Incorrect package

Incorrect package

Correct package

Correct package

  • All paths to files and folders listed in the template manifest (vstemplate file) must be placed relative to it in the archive root.

The contents of an item template are discussed in Creating Visual Studio item templates, project templates are discussed in Creating Visual Studio project templates.

Template distribution

By default, templates are placed in a folder hierarchy as outlined below. “CompanyName” indicates a manually created subfolder where custom templates are stored.

  • TemplateRoot
    • ItemTemplates
      • Visual Basic
      • Visual C#
        • CompanyName
      • Visual Web Developer
    • ProjectTemplates
      • Visual Basic
      • Visual C#
        • CompanyName
      • Visual Web Developer

Changing the default template location is done by opening “Tools → Options” withing Visual Studio and changing the settings shown below.

Changing user template locations

Rather than asking every developer in a company to change their settings manually, a script can be created which changes the registry entries containing the folder paths of interest — the benefit being that misspelling and other human errors are minimized, and that a script can be applied across an entire company by e.g. a system administrator.

The template folder settings are located in “HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0”.

Visual Studio item and templae folder registry values

Shown below is the batch file version of such a script. Although it’s possible to do the same using a .reg-file, due to the hexadecimal notation used in REG_EXPAND_SZ-entries batch files are easier to read and modify.

REG ADD "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0" /v "UserItemTemplatesLocation" /t REG_EXPAND_SZ /d "\\Company\Network\Drive\ItemTemplates" /f
REG ADD "HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\10.0" /v "UserProjectTemplatesLocation" /t REG_EXPAND_SZ /d "\\Company\Network\Drive\ProjectTemplates" /f


Shown below is an example of a deployed item template, and the corresponding insert option in the “Add New Item”-dialog within Visual Studio. As can be seen, the folder in which the template is placed servers as a “subcategory” in the left hand menu, while the template name, description and similar values from the template definition are displayed in their respective locations.

Visual Studio template folder structure

Visual Studio "Add new item"-dialog

A batch file which changes the registry must be run using administrative privileges. An example of such a run is shown below.

4 thoughts on “Deploying Visual Studio templates

  1. Hello, first of all, sorry for my english.

    I create a template project and template item and I want to use in my Shell Isolated, but when I go to File>New>Proyect in Shell Isolated Aplication only appears the option of blank solution.

    I have an Isolated Shell application with VSIX Project for IntelliSense and another VSIX Project for Syntax color. In the Isolated Shell application I want to add a template, if that’s possible. Am I right?.

    I have the example of IronPython VS2010 Isolated Shell, but I don’t understand how it works very well.

    I don’t know if I could explain well, but any questions or assistance would serve me.

    Thank you very much.

    • Hi Fabiana,

      Sorry for taking so long to get back to you on this – I’ve been on holiday for a while 🙂
      Could you send me some additional info to E.g. a screenshot from Visual Studio showing where you want the templates to show up, and a ZIP-file containing the project and/or item templates themselves.


  2. I just created a brand new SC 6.2 site and added the CustomItemGenerator sucroe to my solution as another project. I installed the package into my site, then built the sucroe to overwrite the package’s CustomItemGenerator.dll. I tried to generate custom item classes for a sample dummy template and the generate button doesn’t seem to do anything still.I checked what the button does in the core and saw it calls devtools:generatecustomitem(id=$Target) so I’m thinking maybe something isn’t hooking in. I looked in the CustomItemGeneratorCommand class and saw that if you try to generate custom items on any items other than a template or template folder, there should be a sheer alert in SC, which I don’t get.

    • Hi Lorena,

      I suggest you read this article carefully from start to finish as your comment in no way relates to its contents.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s