How To Create A VSIX Extension For A Custom Template Project

Introduction

 
There are a lot of situations when you start a new project for creating a new WebApi or you need to create a Console App just for test purposes. After you create the project, you realize each time you need to add a set of packages that you always need like: Logging, Swagger, Dependency Injection, AutoMapper, Entity Framework, etc. Or maybe there are new joiners in your company and they are asked to create a new WebApi, but they don’t know what technologies your company uses for different features. The solution for this problem will be to create a custom template for Visual Studio for each project type.
 

How Can the Template Be Shared?

 
One way you can share your project template could be to save the template archive downloadable and to create documentation to indicate where to add the archive in their personal machine in order to be able to see the template in Visual Studio (Visual Studio has a specific folder where all custom templates can be added and see from VS new project window).
 
A more elegant way is to create a VSIX Extension that will install your custom template project in the right location. The file can be shared or uploaded to the Visual Studio gallery. After you get the extension, all you need to do is to install a VSIX file as an extension to your Visual Studio instance.
 
In this example, I will show you how to create a VSIX extension for a WebApi Core project template.
 
Step 1
 
Create your custom project. This project can be of any type: WebApi, Console App, MVC WebApp, WCF Service, etc.
 
Open Visual Studio -> Crate new project -> ASP.NET Core Web Application -> API.
 
How To Create A VSIX Extension For A Custom Template Project
 
Step 2
 
Export your custom project as a Visual Studio Template.
 
How To Create A VSIX Extension For A Custom Template Project
 
For more info on who to export a project template see here.
 
Step 3 - Create a VSIX project
 
To find the VSIX project template, you must install Visual Studio extension development. It can be found in VS installer
 
How To Create A VSIX Extension For A Custom Template Project
 
For more info check here.
 
After you install the Toolset, you need to create a VSIX project.
 
Open Visual Studio -> Create new project -> Empty VSIX Project
 
How To Create A VSIX Extension For A Custom Template Project
 
Step 4
 
Open your source.extension.vsixmanifest file and complete the information
 
Medadata
 
How To Create A VSIX Extension For A Custom Template Project
 
Install Targets
 
This tab refers to the extension compatibility with different versions of Visual Studio. You can leave as it is or you can change the interval setting up, for example, a minimum VS version Microsoft.VisualStudio.Comunity [15.0,). This means the minimum product accepted Visual Studio 17 Community version. For more details on Visual Studio, version number check the link here.
 
How To Create A VSIX Extension For A Custom Template Project
 
Assets
 
This is the tab where we will add our custom template archive. The type of project is Microsoft.VisualStudio.ProjectTemplate, Source could be File or filesystem or you can add a project from the current solution and the path of the archive.
 
How To Create A VSIX Extension For A Custom Template Project
 
How To Create A VSIX Extension For A Custom Template Project
 
Dependencies
 
How To Create A VSIX Extension For A Custom Template Project
 
Prerequisites
 
How To Create A VSIX Extension For A Custom Template Project
 
Step 5 - Build your project
 
Build your project and you will find the VSIX extension in the project binaries. You should have the files above. VSIXProject1.vsix can be installed or shared with your team members.
 
How To Create A VSIX Extension For A Custom Template Project