8
How to create a Visual Studio Project Type
Prepare Your Project
Make sure your project is clean and generic:
- Remove any project-specific code or secrets.
- Replace specific names with placeholders if needed (e.g.,
MyCompany.MyLibrary?TemplateNamespace.MyLibrary).
/ul>
Create a Template Configuration File
In the root of your project, create a .template.config folder and add a template.json file inside it.
Example template.json:
{
"$schema": "http://json.schemastore.org/template",
"author": "Your Name or Company",
"classifications": [ "Library", "C#" ],
"identity": "YourCompany.ClassLibrary.Template",
"name": "My Class Library Template",
"shortName": "myclasslib",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "TemplateNamespace",
"preferNameDirectory": true
}
sourceName: This is the placeholder that will be replaced with the project name when the template is used.shortName: This is the command-line shortcut to use the template.
/ul>
Pack the Template
Use the .NET CLI to pack your template into a .nupkg file:
dotnet new -i . --to distribute dotnet pack --install locally dotnet new -i ./bin/Debug/<your-template>.nupkg
Use the Template
Now you can create a new project using your template:
dotnet new myclasslib -n MyNewLibrary
Optional: Publish to NuGet
If you want others to use your template:
- Create a NuGet account and API key.
- Push your
.nupkgfile:
/ol>
dotnet nuget push <your-template>.nupkg -k <your-api-key> -s https://api.nuget.org/v3/index.json


