This post is about creating project template for the dotnet new command. As part of the new dotnet command, now you can create Empty Web app, API app, MS Test and Solution file as part of dotnet new command. This post is about creating a Web API template with Swagger support.
For creating the template, I already created an Web API project, and enabled swagger. Also I have added EF Core InMemory database support for CRUD operations. Here is the CSProj.
And here is the Startup.cs, ConfigureServices and Configure methods.
Now you need to create one folder and one json file, which is the core for dotnet new template. You need to create .template.config folder and inside that folder you need to create template.json file.
Here is my template.json file.
For more details and possible options you can visit the Wiki page
Once you’re added the file, you can install the template via dotnet command. Here is the syntax.
It will display the list of project templates available with the new template.
Now you can create a new project with your custom template using the following command.
This will create a new project in HelloProjectTemplate folder using your custom template.
Right now there is no direct way to remove the templates, you can modify the template cache json files from C:\Users\[USERNAME]\.templateengine\dotnetcli\v1.0.0
You need to remove the reference from three files inside this directory.
Also you can run the dotnet new --debug:reinit command to re-initialize your environment.
You can deploy your template via nuget.
Happy Programming :)
What do you think? I would like to hear your thoughts, suggestions, and questions in the comments section below.
Did you like this article? Share it with your friends