.NET CLI

The .NET command-line interface (CLI) is a cross-platform toolchain for developing, building, running, and publishing .NET applications. It is included with the .NET SDK.

Common CLI commands

SDK information

Display the active SDK version

dotnet --version

Displays the active .NET SDK version.

Display SDK and runtime information

dotnet --info

Displays detailed information about the installed SDKs, runtimes, and environment.

Solution and project commands

Create a project from a template

dotnet new <template>

Creates a new project from a template, such as console, webapi, or classlib.

Create a console project

dotnet new console --output MyProject

Creates a new console project in the MyProject directory.

Create a solution

dotnet new sln --output MySolution

Creates a new solution in the MySolution directory.

List installed templates

dotnet new list

Lists the project templates installed on the machine.

Add a project to a solution

dotnet sln add <project>

Adds a project to a solution file.

NuGet and project references

Restore dependencies

dotnet restore

Restores the NuGet packages required by a project or solution.

Add a NuGet package

dotnet add package <package>

Adds a NuGet package reference to a project.

Remove a NuGet package

dotnet remove package <package>

Removes a NuGet package reference from a project.

Add a project reference

dotnet add reference <project>

Adds a project-to-project reference.

Remove a project reference

dotnet remove reference <project>

Removes a project-to-project reference.

Build, run, and test commands

Build a project or solution

dotnet build

Compiles the project or solution and produces its build output.

Run a project

dotnet run

Builds and runs a project from its source directory.

Run tests

dotnet test

Builds and runs the tests in a project or solution, then reports the results.

Publish and cleanup commands

Publish an application

dotnet publish

Compiles the application and prepares its files for deployment.

Clean build output

dotnet clean

Removes the previous build output from a project or solution.

Most commands accept a project or solution path, for example dotnet build MyApp.csproj or dotnet test MySolution.sln.

You can find the list CLI Commands on .NET CLI | Microsoft Learn