Creating tagged templates in Visual Studio to efficiently search and group users

Original author: Soojin Choi
  • Transfer
  • Tutorial
Visual Studio project templates allow developers to more efficiently create several similar projects by defining a common set of initial files. Project templates can be fully customized according to the needs of the development team or group and can be published in the Visual Studio Marketplace for download and use by other people! After publishing, developers can install the template and access it through the New Project dialog box in Visual Studio.

The newly developed New Project dialog box for Visual Studio 2019 was created to help developers get to their code faster.. Using the search and filtering experience, we strive to provide the best detection for specific patterns so that you can start developing your application faster.

image

In this walkthrough, you will learn:

  • Create a project template
  • Add tags or filters to the project template
  • Deploy a template as an extension with a VSIX project template

Before you begin, please make sure that you have installed Visual Studio 2019 with the Visual Studio SDK .

Creating a project template


There are several ways to create a project template, but in this walkthrough we will create a C # project template using the New Project dialog box.

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

Adding tags / filters to your project template


Once you have created a project template, you can add a tag or filters to it in the template .vstemplate of the XML file.

  1. Add the built-in Visual Studio tags as well as any custom tags to the project template using the LanguageTag , PlatformTag , ProjectTypeTag elements in the TemplateData section and save the file. For example, as highlighted in the screenshot below:

    image
  2. Save and close the vstemplate xml file .

Deploying a template as an extension using the VSIX project template


Wrap the project template in the VSIX project template to expand it as an extension.

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

  2. Set VSIX Project as the project to start.

    In Solution Explorer, right-click on the VSIX project and select Set as StartUp Project . Your Solution Explorer should now look something like this (with the bold VSIX project highlighted):

    image
  3. Add the project template as an asset to the VSIX project.
    • Click Assets and select New .
    • Set the Type field to Microsoft.VisualStudio.ProjectTemplate .
    • Set the Source field as A project in current solution .
    • Set the Project field as the project template.

      image
    • Click OK, then save and close the source.extension.vsixmanifest file .
  4. Run the code without calling the debugger ( CTRL + F5 )

Like this! A new project template will appear in the New Project dialog box with tags below the template description and filters enabled by these tags. You can also take one more step and easily publish your project template on the Visual Studio Marketplace (and while you are there, also try the cool features of Visual Studio 2019 and please let us know what you think about it)! Here is an example of one of the existing extensions - Textmate Grammar Template .

Any suggestions?


We continue to work on our tools, and for this we need your help! Please share your feedback / comments below, either through the Developer Community Visual Studio, or by tweeting to our @VisualStudio team.

Also popular now: