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.
- In Visual Studio, launch the New Project Dialog File > New > Project (or use the keyboard shortcut, CTRL + SHIFT + N).
- Filter the list by Project type > Extensions and select C# Project Template.
- 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.
-
- 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. - Save and close the vstemplate the XML file.
- Add Visual Studio’s built-in tags as well as any custom tags to your project template using
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.
- 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.
-
- 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):
- Add your project template as an asset to the VSIX project.
- Click on the Assets tab and select the New button.
- Set the Type field as Microsoft.VisualStudio.ProjectTemplate.
- Set the Source field as A project in current solution.
- Set the Project field as your project template.
- Click OK, then save and close the source.extension.vsixmanifest file.
- 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.
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...
How do I add those tags to an existing custom App Wizard?
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!
Hi Soojin,
Unfortunatelly, I have an older App Wizard, VSZ based, so it will not work for me.
Thanks, Nenad
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.
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.
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...
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!
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’
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!
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.
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!
@SoojinChoi
Are PlatformTag & ProjectTypeTag free-form nodes?
Also I thinkj @DeanJackson’s question deserves to be answered too.
Hi Yann, yes, all three tag elements are free-form. 🙂
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.
Hi Veselin, this will work in our most recent update in our preview channel, specifically in Visual Studio 2019 16.1 Preview 2. Thank you!
Thank you!
You’re probably more likely to get an answer if you specify what part didn’t work.
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) ??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!