Manage .NET project and item templates

.NET provides a template system that enables users to install or uninstall packages containing templates from NuGet, a NuGet package file, or a file system directory. This article describes how to manage .NET templates through the .NET SDK CLI.

For more information about creating templates, see Tutorial: Create templates.

Install template

Template packages are installed through the dotnet new install SDK command. You can either provide the NuGet package identifier of a template package, or a folder that contains the template files.

NuGet hosted package

.NET CLI template packages are uploaded to NuGet for wide distribution. Template packages can also be installed from a private feed. Instead of uploading a template package to a NuGet feed, nupkg template files can be distributed and manually installed, as described in the Local NuGet package section.

For more information about configuring NuGet feeds, see dotnet nuget add source.

To install a template package from the default NuGet feed, use the dotnet new install {package-id} command:

dotnet new install Microsoft.DotNet.Web.Spa.ProjectTemplates

To install a template package from the default NuGet feed with a specific version, use the dotnet new install {package-id}::{version} command:

dotnet new install Microsoft.DotNet.Web.Spa.ProjectTemplates::2.2.6

Local NuGet package

When a template package is created, a nupkg file is generated. If you have a nupkg file containing templates, you can install it with the dotnet new install {path-to-package} command:

dotnet new install c:\code\nuget-packages\Some.Templates.1.0.0.nupkg
dotnet new install ~/code/nuget-packages/Some.Templates.1.0.0.nupkg

Folder

As an alternative to installing template from a nupkg file, you can also install templates from a folder directly with the dotnet new install {folder-path} command. The folder specified is treated as the template package identifier for any template found. Any template found in the specified folder's hierarchy is installed.

dotnet new install c:\code\nuget-packages\some-folder\
dotnet new install ~/code/nuget-packages/some-folder/

The {folder-path} specified on the command becomes the template package identifier for all templates found. As specified in the List template packages section, you can get a list of template packages installed with the dotnet new uninstall command. In this example, the template package identifier is shown as the folder used for install:

dotnet new uninstall
Currently installed items:

... cut to save space ...

  c:\code\nuget-packages\some-folder
    Templates:
      A Template Console Class (templateconsole) C#
      Project for some technology (contosoproject) C#
    Uninstall Command:
      dotnet new uninstall c:\code\nuget-packages\some-folder
dotnet new uninstall
Currently installed items:

... cut to save space ...

  /home/username/code/templates
    Templates:
      A Template Console Class (templateconsole) C#
      Project for some technology (contosoproject) C#
    Uninstall Command:
      dotnet new uninstall /home/username/code/templates

Uninstall template package

Template packages are uninstalled through the dotnet new uninstall SDK command. You can either provide the NuGet package identifier of a template package, or a folder that contains the template files.

NuGet package

After a NuGet template package is installed, either from a NuGet feed or a nupkg file, you can uninstall it by referencing the NuGet package identifier.

To uninstall a template package, use the dotnet new uninstall {package-id} command:

dotnet new uninstall Microsoft.DotNet.Web.Spa.ProjectTemplates

Folder

When templates are installed through a folder path, the folder path becomes the template package identifier.

To uninstall a template package, use the dotnet new uninstall {package-folder-path} command:

dotnet new uninstall c:\code\nuget-packages\some-folder
dotnet new uninstall /home/username/code/templates

List template packages

By using the standard uninstall command without a package identifier, you can see a list of installed template packages along with the command that uninstalls each template package.

dotnet new uninstall
Currently installed items:

... cut to save space ...

  c:\code\nuget-packages\some-folder
    Templates:
      A Template Console Class (templateconsole) C#
      Project for some technology (contosoproject) C#
    Uninstall Command:
      dotnet new uninstall c:\code\nuget-packages\some-folder

Install template packages from other SDKs

If you've installed each version of the SDK sequentially, for example you installed SDK 6.0, then SDK 7.0, and so on, you'll have every SDK's templates installed. However, if you start with a later SDK version, like 7.0, only the templates for this version are included. Templates for any other release aren't included.

The .NET templates are available on NuGet, and you can install them like any other template. For more information, see Install NuGet hosted package.

SDK NuGet Package Identifier
.NET Core 2.1 Microsoft.DotNet.Common.ProjectTemplates.2.1
.NET Core 2.2 Microsoft.DotNet.Common.ProjectTemplates.2.2
.NET Core 3.0 Microsoft.DotNet.Common.ProjectTemplates.3.0
.NET Core 3.1 Microsoft.DotNet.Common.ProjectTemplates.3.1
.NET 5.0 Microsoft.DotNet.Common.ProjectTemplates.5.0
.NET 6.0 Microsoft.DotNet.Common.ProjectTemplates.6.0
.NET 7.0 Microsoft.DotNet.Common.ProjectTemplates.7.0
.NET 8.0 Microsoft.DotNet.Common.ProjectTemplates.8.0
.NET 9.0 Microsoft.DotNet.Common.ProjectTemplates.9.0
ASP.NET Core 2.1 Microsoft.DotNet.Web.ProjectTemplates.2.1
ASP.NET Core 2.2 Microsoft.DotNet.Web.ProjectTemplates.2.2
ASP.NET Core 3.0 Microsoft.DotNet.Web.ProjectTemplates.3.0
ASP.NET Core 3.1 Microsoft.DotNet.Web.ProjectTemplates.3.1
ASP.NET Core 5.0 Microsoft.DotNet.Web.ProjectTemplates.5.0
ASP.NET Core 6.0 Microsoft.DotNet.Web.ProjectTemplates.6.0
ASP.NET Core 7.0 Microsoft.DotNet.Web.ProjectTemplates.7.0
ASP.NET Core 8.0 Microsoft.DotNet.Web.ProjectTemplates.8.0
ASP.NET Core 9.0 Microsoft.DotNet.Web.ProjectTemplates.8.0

For example, the .NET 9 SDK includes templates for a console app targeting .NET 9. If you wanted to target .NET Core 3.1, you would need to install the 3.1 template package.

  1. Try creating an app that targets .NET Core 3.1.

    dotnet new console --framework netcoreapp3.1
    

    If you see an error message, you need to install the templates.

  2. Install the .NET Core 3.1 project templates.

    dotnet new install Microsoft.DotNet.Common.ProjectTemplates.3.1
    
  3. Try creating the app a second time.

    dotnet new console --framework netcoreapp3.1
    

    And you should see a message indicating the project was created.

    The template "Console Application" was created successfully.
    
    Processing post-creation actions...
    Running 'dotnet restore' on path-to-project-file.csproj...
      Determining projects to restore...
      Restore completed in 1.05 sec for path-to-project-file.csproj.
    
    Restore succeeded.
    

See also