Build Visual Studio templates with tags, for efficient user search and grouping

Avatar

Visual Studio’s project templates enable you, the developer, to create multiple similar projects more efficiently by defining a common set of starter files. The project templates can be fully customized to meet the needs of a development team, or a group, and can be published to the Visual Studio Marketplace for others to download and use too! Once published, developers can install and access the template through Visual Studio’s New Project Dialog.

The newly designed New Project Dialog for Visual Studio 2019 was built to help developers get to their code faster. Using a search and filter focused experience, we are aiming to provide better discoverability for specific templates to start your application development. 

 

In this walkthrough, you will learn to 

  • Create a project template 
  • Add tagor filters to the project template 
  • Deploy the template as an extension using the VSIX project template 

Before getting started, please make sure you have installed Visual Studio 2019 with Visual Studio SDK. 

 

Creating a project template 

There are a few ways you can create a project template, but in this walkthrough, we will create a C# project template using the New Project Dialog. 

  1. In Visual Studio, launch the New Project Dialog File New > Project
    (or use the keyboard shortcutCTRL + SHIFT + N).
  2. Filter the list by Project type Extensions and select C# Project Template.
  3. Click Next then modify the Project name field and click Create.

 

Adding tags / filters to your project template 

Once you’ve created a project template, you can add tags or filters to it in the template’s .vstemplate XML file. 

    1. Add Visual Studio’s built-in tags as well as any custom tags to your project template using <LanguageTag>, <PlatformTag>, <ProjectTypeTag> elements under <TemplateData> and save the file. For example, as highlighted below:
      A list of our built-in tags can be found in our docs, but another way we’ve seen extenders implement this and would work is having their brand name under the Project Type category.
    2. Save and close the vstemplate the XML file. 

 

Deploying the template as an extension using the VSIX project template 

Wrap your project template in a VSIX project template to deploy your template as an extension. 

  1. Create an Empty VSIX Project in the Solution created for the C# project template above.
      1. In the Solution Explorer, right click on the Solution and select Add > New Project.
      2. Type “vsix” in the search box and select Empty VSIX Project for C# (or VSIX Project if you are using earlier versions of Visual Studio).
      3. Click Next then modify the Project name field and click Create.

     

  2. Set the VSIX Project as a startup project.
    In the Solution Explorer, right click on the VSIX project and select Set as StartUp Project. Your Solution Explorer should now look something like this (with your VSIX project bolded):
     
  3. Add your project template as an asset to the VSIX project.
    1. Click on the Assets tab and select the New button.
    2. Set the Type field as Microsoft.VisualStudio.ProjectTemplate.
    3. Set the Source field as A project in current solution.
    4. Set the Project field as your project template.
    5. Click OK, then save and close the source.extension.vsixmanifest file. 
  4. Run your code without invoking the debugger (CTRL + F5) 

That’s it! Your new project template will appear in the New Project dialog with the tags under your template’s description and filters enabled by those tags. You can also take it a step further and easily publish your project template to the Visual Studio Marketplace (and while you’re at it, also try out the little great things about Visual Studio 2019 and please let us know what you think)! Here is an example of one in an existing extensionTextmate Grammar Template. 

Have suggestions? 

We are continuing to work on our tools and to do that, we could use your help! Please share your feedback/comments below, or through the Visual Studio Developer Community, or tweet at our team @VisualStudio. 

Avatar
Soojin Choi

Program Manager, Visual Studio Platform

Follow    

21 Comments
Avatar
Dean Jackson 2019-04-19 10:09:04
Aren't you at least going to mention what the other ways to create templates are??  Why do you have to manually edit the template file when adding the tags: <LanguageTag>, <PlatformTag> ...aren't you going to make these simple properties we can set using Visual Studio (like a properties page) ??
Avatar
anonymous 2019-04-22 05:18:29
This comment has been deleted.
Avatar
Veselin Ivanov 2019-04-24 04:05:28
Guys, is this suppose to work with Visual Studio 2019 16.0.0? I tried to create a project template following the steps in this article but the tags do not appear in the New Project dialog.
Avatar
Yann Duran 2019-04-24 17:31:39
@SoojinChoi Are PlatformTag & ProjectTypeTag free-form nodes? Also I thinkj @DeanJackson's question deserves to be answered too.
Avatar
Robert van der Hulst 2019-04-25 13:11:45
Can't get this to work with 16.1.0 Preview 2.0I have added the tags to our templates but the language, platform and projecttype tags are not shown and not included in the dropdowns on the new project dialog.
Avatar
kosmo kosmowski 2019-04-25 14:43:22
Are you sure this is available to public? On latest vs2019 and latest SDK it doesn't work. It just shows warnings:The element 'TemplateData' in namespace 'http://schemas.microsoft.com/developer/vstemplate/2005' has invalid child element 'LanguageTag'
Avatar
Arpad Stoever 2019-04-29 07:35:06
Hi, Soojin Choi, thank you very much for your tutorial to build VS templates. But what is it good for? I followed the example and built an example Template. And I made some change to the template which I would like to appear when I use the template in the new project I create using this template. So I added some folders, some files and some dependencies and created a .visx project. ANd - heureka - my template appeared in the list. But - when I used it to create a new project I simply got a naked project without any of the files, folders and dependencies I´d added to the template. So - what is it good for?  By the way - the filtering via tags does not work. As soon as I use on of the filter tags I added my template disappeares from the list. And the element 'LanguageTag' creates a warning of Invalid childelement in element 'TemplateData'.  I am using VS 2019 Community edition V16.0.0.2 But anyways, thank you for your efforts.
Avatar
Jakub Míšek 2019-05-01 06:36:48
Is it possible to have `<LanguageTag>` with the value of `PHP` (or anything that is not predefined in vs2019) ? We are extension developers and our projects templates cannot be filtered. It worked well in previous version of VS (98, up to 2017) since the New project dialog respected custom language names.
Avatar
Nenad Stefanović 2019-05-02 20:55:50
How do I add those tags to an existing custom App Wizard?
Avatar
Loz Groves 2019-06-08 08:03:22
This is a fantastic addition for us Extension developers (after all the bad feedback from 'us' about the new dialog). I've noticed that VS doesn't consolidate all the names in the drop-downs though. So when my template language is 'C#', I get an additional entry in the list. The same is true for the 'Project Type' and 'Platform'. If this isn't fixed, I can see never ending lists evolving of extensions as people use this feature. It even started to go wrong in 16.1.1 when there was a duplicate 'Extensions' type added (by one of your own templates, I believe)!! EDIT: It turns out that if you use 'CSharp' for LanguageTag, that solves the problem. Free form text isn't consolidated. And it would be nice if the lists were alphabetically sorted!!