.NET CLI

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

→ docs, code

Content

General commands

CommandAction

dotnet -v

Display information on the installed version

New command

CommandAction

dotnet new

View the available templates (see docs.microsoft.com)

Examples:

  • dotnet new webapi --output src/PalTracker --name PalTracker will use the template "ASP.NET Core Web API"

  • dotnet new xunit --output test/PalTrackerTests --name PalTrackerTestswill use the template "xUnit Test Project"

  • dotnet new sln --name PalTracker will use the template "Solution File"

Add command

CommandAction

dotnet add reference

Adds project-to-project (P2P) references (see docs.microsoft.com)

dotnet add package

Adds a package reference to a project file (see docs.microsoft.com)

Examples:

  • dotnet add test/PalTrackerTests reference src/PalTracker/PalTracker.csproj

  • dotnet add test/PalTrackerTests package Microsoft.AspNetCore.TestHost --version 2.2.0

Solution command

CommandAction

dotnet sln

Modifies a .NET Core solution file (see docs.microsoft.com)

Examples:

  • dotnet sln PalTracker.sln add src/PalTracker/PalTracker.csproj

Run command

CommandAction

dotnet run

Runs source code without any explicit compile or launch commands (see docs.microsoft.com)

Examples:

  • dotnet run --project src/PalTracker

Publish command

CommandAction

dotnet publish

Packs the application and its dependencies into a folder for deployment to a hosting system (see docs.microsoft.com)

Examples:

  • dotnet publish src/PalTracker --configuration Release

Test command

CommandAction

dotnet test

Run the tests (see docs.microsoft.com)

Examples:

  • dotnet test test/PalTrackerTests --filter PalTrackerTests.InMemoryTimeEntryRepositoryTest

See also:

Tools

Last updated