dotnet new - .NET CLI (original) (raw)

This article applies to: ✔️ .NET Core 3.1 SDK and later versions

Name

dotnet new - Creates a new project, configuration file, or solution based on the specified template.

Synopsis

dotnet new <TEMPLATE> [--dry-run] [--force] [-lang|--language {"C#"|"F#"|VB}]
    [-n|--name <OUTPUT_NAME>] [-f|--framework <FRAMEWORK>] [--no-update-check]
    [-o|--output <OUTPUT_DIRECTORY>] [--project <PROJECT_PATH>]
    [-d|--diagnostics] [--verbosity <LEVEL>] [Template options]

dotnet new -h|--help

Description

The dotnet new command creates a .NET project or other artifacts based on a template.

The command calls the template engine to create the artifacts on disk based on the specified template and options.

Note

Starting with the .NET 7 SDK, the dotnet new syntax has changed:

Other options that were available before are still available to use with their respective subcommands. Separate help for each subcommand is available via the -h or --help option: dotnet new <subcommand> --help lists all supported options for the subcommand.

Additionally, tab completion is now available for dotnet new. It supports completion for installed template names and for the options a selected template provides. To activate tab completion for the .NET SDK, see Enable tab completion.

Tab completion

Starting with .NET SDK 7.0.100, tab completion is available for dotnet new. It supports completion for installed template names, as well as completion for the options a selected template provides. To activate tab completion for the .NET SDK, see Enable tab completion.

Implicit restore

You don't have to run dotnet restore because it's run implicitly by all commands that require a restore to occur, such as dotnet new, dotnet build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To disable implicit restore, use the --no-restore option.

The dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.

For information about how to manage NuGet feeds, see the dotnet restore documentation.

Arguments

The following table shows the templates that come pre-installed with the .NET SDK. The default language for the template is shown inside the brackets. Click on the short name link to see the specific template options.

Templates Short name Language Tags Introduced
Console Application console [C#], F#, VB Common/Console 1.0
Class library classlib [C#], F#, VB Common/Library 1.0
WPF Application wpf [C#], VB Common/WPF 3.0 (5.0 for VB)
WPF Class library wpflib [C#], VB Common/WPF 3.0 (5.0 for VB)
WPF Custom Control Library wpfcustomcontrollib [C#], VB Common/WPF 3.0 (5.0 for VB)
WPF User Control Library wpfusercontrollib [C#], VB Common/WPF 3.0 (5.0 for VB)
Windows Forms (WinForms) Application winforms [C#], VB Common/WinForms 3.0 (5.0 for VB)
Windows Forms (WinForms) Class library winformslib [C#], VB Common/WinForms 3.0 (5.0 for VB)
Worker Service worker [C#] Common/Worker/Web 3.0
MSTest Test Project mstest [C#], F#, VB Test/MSTest 1.0
MSTest Test Class mstest-class [C#], F#, VB Test/MSTest 1.0
NUnit 3 Test Project nunit [C#], F#, VB Test/NUnit 2.1.400
NUnit 3 Test Item nunit-test [C#], F#, VB Test/NUnit 2.2
xUnit Test Project xunit [C#], F#, VB Test/xUnit 1.0
Razor Component razorcomponent [C#] Web/ASP.NET 3.0
Razor Page page [C#] Web/ASP.NET 2.0
MVC ViewImports viewimports [C#] Web/ASP.NET 2.0
MVC ViewStart viewstart [C#] Web/ASP.NET 2.0
Blazor Web App blazor [C#] Web/Blazor 8.0.100
Blazor WebAssembly Standalone App blazorwasm [C#] Web/Blazor/WebAssembly/PWA 3.1.300
ASP.NET Core Empty web [C#], F# Web/Empty 1.0
ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC 1.0
ASP.NET Core Web App webapp, razor [C#] Web/MVC/Razor Pages 2.2, 2.0
Razor Class Library razorclasslib [C#] Web/Razor/Library/Razor Class Library 2.1
ASP.NET Core Web API webapi [C#], F# Web/Web API/API/Service/WebAPI 1.0
ASP.NET Core API webapiaot [C#] Web/Web API/API/Service 8.0
ASP.NET Core API controller apicontroller [C#] Web/ASP.NET 8.0
ASP.NET Core gRPC Service grpc [C#] Web/gRPC 3.0
dotnet gitignore file gitignore Config 3.0
global.json file globaljson Config 2.0
NuGet Config nugetconfig Config 1.0
Dotnet local tool manifest file tool-manifest Config 3.0
Web Config webconfig Config 1.0
Solution File sln Solution 1.0
Protocol Buffer File proto Web/gRPC 3.0
EditorConfig file editorconfig Config 6.0

The following table shows templates that have been discontinued and no longer come pre-installed with the .NET SDK. Click on the short name link to see the specific template options.

Templates Short name Language Tags Discontinued since
ASP.NET Core with Angular angular [C#] Web/MVC/SPA 8.0
ASP.NET Core with React.js react [C#] Web/MVC/SPA 8.0
Blazor Server App blazorserver [C#] Web/Blazor 8.0
Blazor Server App Empty blazorserver-empty [C#] Web/Blazor 8.0
Blazor WebAssembly App Empty blazorwasm-empty [C#] Web/Blazor/WebAssembly 8.0

Options

Template options

Each template may have additional options defined. For more information, see .NET default templates for dotnet new.

Examples

dotnet new console  
dotnet new console --language "F#"  
dotnet new classlib --framework "netstandard2.0" -o MyLibrary  
dotnet new mvc -au None  
dotnet new xunit  
dotnet new globaljson --sdk-version 8.0.101 --roll-forward latestFeature  
dotnet new console -h  
dotnet new console --language "F#" -h  

See also