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?
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.

Step 2
Export your custom project as a Visual Studio Template.

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

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

Step 4
Open your source.extension.vsixmanifest file and complete the information
Medadata

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.

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.


Dependencies

Prerequisites

Step 5 - Build your project

Pui YipPosted May 24, 2023, 5:00 AM
Is it possible to have a list of options e.g. Logging, Swagger, Dependency Injection, AutoMapper, Entity Framework, etc that the users can select what they want when at the time creat the new project?
Edward ProchakPosted Oct 14, 2021, 2:18 PM
Missing the last step, how do users install it? Is there a specific location to run the VSIX installer? I'm specifically considering users with more than one copy of Visual Studio installed.
Roshan RathodPosted Jul 23, 2020, 10:37 PM
Nice one..