Overview

The .NET CLI is a cross-platform toolchain for developing, building, running, and publishing .NET apps.

At the heart of the toolchain is the dotnet driver, responsible for running framework-dependent apps or executing a command.

Commands follow this general structure: dotnet <command> [option] [argument]

CLI commands

Basic commands

  • dotnet new — creates a new project, configuration file, or solution.
  • dotnet restore — restores the dependencies and tools of a project.
  • dotnet build — builds a project and its dependencies.
  • dotnet publish — publishes the app and its dependencies to a folder for deployment to a hosting system.
  • dotnet run — runs source code.
  • dotnet test — executes unit tests.
  • dotnet vstest — packs code into a NuGet package.
  • dotnet clean — cleans the output of a project.
  • dotnet sln — lists or modifies the projects in a .NET solution file.
  • dotnet store — stores assemblies in the runtime package store.
  • dotnet watch — when changes in source code are detected, either restart, hot reload, or run a specified dotnet command.
  • dotnet format — formats code to match EditorConfig settings.

Project management commands

  • list|add|remove package
  • list|add|remove reference

NuGet package management commands

Workload management commands

  • workload clean — clean up workload packs leftover from .NET SDK/Visual Studio updates where installation records for the pack no longer exist
    • --all — more aggressive; cleans every pack of the current SDK workload installation type
  • workload install <WORKLOAD_ID> — Install one or more workloads.
  • workload list — List workloads available.
  • workload repair — Repair workload installations.
  • workload restore <PROJECT | SOLUTION> — Restore workloads required for a project.
  • workload search <SEARCH_STRING> — Search for available workloads.
  • workload uninstall <WORKLOAD_ID> — Uninstall one or more workloads.
  • workload update — Update all installed workloads.

Tool management commands

.NET tools are NuGet packages that contain console applications.

More notes: tools

More information: https://learn.microsoft.com/en-us/dotnet/core/tools/global-tools

Advanced commands

  • sdk check — lists the latest available version of the .NET SDK and .NET runtime for each feature band.
  • msbuild — allows access to an MSBuild. Running dotnet msbuild -restore is equivalent to dotnet build.
  • build-server — manages build servers.
  • dev-certs — generates a self-signed certificate to enables HTTPS use in development.

Commonly used commands

Getting Information

dotnet --info # List information on .NET installation, machine environment, etc
dotnet --list-runtimes # List the installed .NET runtimes.
dotnet --list-sdks # List the installed .NET SDKs.
dotnet new --list # List currently installed templates.