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 tags or 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 shortcut, CTRL + 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:


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.

  • In the Solution Explorer, right click on the Solution and select Add > New Project.
  • 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).
  • 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 extension, Textmate 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

Комментарии (0)