Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / templates

Custom Category for Visual Studio Templates

4.91/5 (3 votes)
28 Nov 2014CPOL2 min read 11.2K  
A way to add a custom category for your Visual Studio Templates

Introduction

This seems like a trivial task. And it is. Still it's not easy to find where and what should be changed or to find it explained on MSDN. Even searching it on Google will not easily help. Once your template project is added, and no matter if it is a project template or an item template, you will find your .vstemplate file. If you right click on the template file and choose properties, you will get to the following screen:

Image 1

As you can see from this picture, there is a property called Category and it is the one to be set.

The result will be the following (in case of an Item Template):

Image 2

In case you have problems seeing your changes, make sure you cleaned and rebuilt the solution and that you reset your VS Experimental instance. More details about this procedure can be found here.

Note that I had trouble with this approach on Visual Studio Ultimate 2015 Preview (Version 14.0.22310.1 DP) and I already notified a possible bug to Microsoft. It works as expected on VS 2012 and 2013.

Managing Multiple Items within a Same Group

In case your Visual Studio Item Template project contains multiple item templates and you want to have a single place for editing the categories, you can make use of the following technique.

XML
<!--?xml version="1.0" encoding="utf-8"?-->
<project defaulttargets="Build" toolsversion="4.0" 
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <propertygroup>
    ...
    <templatecategory>StyleCop Analyzers</templatecategory>
  </propertygroup>

Now in the same file search for all of the references to your VSTemplate files and change them in the following way:

XML
<vstemplate include="DiagnosticAnalyzerTemplate.vstemplate">
      <outputsubpath>$(TemplateCategory)</outputsubpath>
      <subtype>Designer</subtype>

Now repeat the same for all the templates you would like to be a part of the group you just defined. In case the group name is going to change, you will need to edit only a single place in your project file.

This can be useful in case you are managing a substantial number of templates and you are changing categories based on your product version.

Cheers!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)