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

Comments are closed.

  • Avatar
    Dean Jackson

    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
      Soojin Choi

      Hi Dean, here is a link to our docs page that explains ways you can create project templates. Due to engineering constraints, the only way to add tags to your new (or existing) templates is using the <…Tag> elements in the .vstemplate file. That said, please file a suggestion ticket in our Developer Community on making the tags properties, as community input helps to prioritize our work. Thank you!

  • Avatar
    Veselin Ivanov

    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

    @SoojinChoi
    Are PlatformTag & ProjectTypeTag free-form nodes?
    Also I thinkj @DeanJackson’s question deserves to be answered too.

  • Avatar
    Robert van der Hulst

    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
      Soojin Choi

      Hi Robert, we’d love to help you add tags to your templates. To do that, could you please provide a more detailed repro steps here by clicking on “Report a problem”? Thank you!

  • Avatar
    kosmo kosmowski

    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
      Soojin Choi

      Hi Kosmo, yes, this is available to public in our preview channel, specifically Visual Studio 2019 16.1 Preview 2. If you’re still unable to add tags to your templates, could you please provide a detailed repro steps here by clicking on “Report a problem”? Thank you!

  • Avatar
    Arpad Stoever

    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
      Soojin Choi

      Hi Arpad, thank you for the feedback. The ability to add tags is currently available in our latest preview, specifically v16.1 Preview 2, and is not available for v16.0.0.2. As for the vsix project, your added folders/files/dependencies should have been saved for future use. If that wasn’t the case, could you please provide a detailed repros steps here by clicking on “Report a problem”? This will help us to assist further. Thank you!

  • Avatar
    Jakub Míšek

    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
      Soojin Choi

      Hi Jakub, yes it is possible to have custom values for the tags! 🙂 If you add a <LanguageTag> with a value of PHP Visual Studio will (1) add the tag to your template item and (2) add the value PHP to the Language filter dropdown.

    • Avatar
      Soojin Choi

      Hi Nenad, you should be able to access the .vstemplate file. That said, the ability to add tags does not work for older App Wizards (e.g. VSZ-style template). Could you please provide us with a sample code? Thank you!

      • Avatar
        Nenad Stefanović

        Hi Soojin,
        Unfortunatelly, I have an older App Wizard, VSZ based, so it will not work for me.
        Thanks, Nenad

  • Avatar
    Loz Groves

    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!!