Creating a custom project template for use with dotnet CLI


Docs: HERE

  • Create a directory .template.config in the same directory as the .csproj file.
  • Create a template.json file inside the above directory
  • To install this as a template:
# The directory structure inside folder-containing-csproj:
# project.csproj
# .template.config/template.json
dotnet new -i /path/to/folder-containing-csproj

NOTE successful install just echoes back dotnet new help text:

You can pack the template for distro:

  • in the directory containing .csproj, create a nuspec file (nuget spec)
  • make sure the file has this section:
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="">
    <!--other tags omitted for brevity-->
      <packageType name="Template" />
  • now run nuget pack
  • install this as a template by running dotnet new -i /path/to/nupkg-file

List of available templates

  • Found here
  • Interesting ones:
    • dotnet new caju - clean architecture with event sourcing / hexagonal architecture

Uninstall package

  • get the name right by running dotnet new -u: this will list installed
  • run dotnet new -u name