dotnet
Run, build, and manage .NET applications
TLDR
Initialize a new .NET project
Restore NuGet packages
Build and execute the .NET project in the current directory
Run a packaged dotnet application (only needs the runtime, the rest of the commands require the .NET Core SDK installed)
SYNOPSIS
dotnet [options] [command] [arguments]
PARAMETERS
[options]
Global options that apply to the dotnet command itself, rather than a specific subcommand. For example, --info
provides detailed information about the .NET environment.
[command]
The action to perform. This is the core functionality, such as build
, run
, publish
, test
, or new
. Each command has its own specific options and arguments.
[arguments]
Arguments passed to the specific command or application being executed. For instance, in dotnet run --project myapp.csproj
, myapp.csproj
is an argument for the run
command.
--info
Displays detailed information about the .NET SDKs, runtimes, and environment variables currently installed.
--version
Prints the version of the .NET SDK in use.
--help
Shows command-line help for the specified command or global options if no command is given.
new
Creates a new .NET project, configuration file, or solution based on a template (e.g., dotnet new console
).
restore
Restores the NuGet packages for a project. This command is typically implicitly run by other commands like build
and run
.
build
Builds a project and all its dependencies. Compiles source code into an executable or library.
run
Executes source code directly without any explicit compile or launch commands. Useful for local development and testing.
publish
Publishes the application and its dependencies to a folder for deployment. Creates a deployable package.
test
Runs tests from a specified project using a test runner (e.g., xUnit, NUnit).
add
Adds a package reference or project reference to a project file (e.g., dotnet add package Newtonsoft.Json
).
remove
Removes a package reference or project reference from a project file.
tool
Manages .NET global, local, and project-specific tools (e.g., dotnet tool install --global some-tool
).
DESCRIPTION
The dotnet command is the primary command-line interface (CLI) for developing, building, running, and publishing .NET applications across various operating systems, including Linux, Windows, and macOS. It serves as a unified entry point for all .NET SDK functionalities.
Developers use dotnet to manage project files, restore NuGet packages, compile source code, execute applications, run tests, and deploy their software. It abstracts away much of the underlying build system complexity, providing a consistent experience regardless of the project type (console apps, web APIs, desktop applications, etc.).
The command allows for highly automated workflows, making it a cornerstone for continuous integration and deployment (CI/CD) pipelines. Its modular design, relying on SDKs and runtimes, enables developers to target specific .NET versions and ensure application compatibility.
CAVEATS
While dotnet offers cross-platform consistency, subtle differences in file paths, environment variables, and native library dependencies can still cause issues between operating systems. Versioning conflicts between installed SDKs and runtimes can also be complex, requiring careful management, especially when working on multiple projects targeting different .NET versions. Containerization (e.g., Docker) is often used to mitigate these environment-specific challenges.
SDKS AND RUNTIMES
The dotnet CLI relies on SDKs (Software Development Kits), which include all necessary components for developing (compiler, build tools, CLI), and Runtimes, which are only needed to execute applications. Users install SDKs for development, and often only runtimes for deployment environments.
PROJECT FILES (.CSPROJ)
The behavior of dotnet commands is primarily driven by the project file (e.g., .csproj
for C#, .fsproj
for F#). These XML-based files define project properties, dependencies, and build configurations, enabling the CLI to understand how to process and build the application.
HISTORY
The dotnet command is a cornerstone of .NET Core, which was first released in 2016 as an open-source, cross-platform successor to the proprietary, Windows-only .NET Framework. The CLI was designed from the ground up to be portable and efficient, addressing the need for .NET applications to run seamlessly on Linux and macOS servers and desktops. Its development marked a significant shift in Microsoft's strategy, embracing open-source principles and community contributions. With the release of .NET 5 in 2020, .NET Core officially superseded .NET Framework, consolidating the platform under a single, unified dotnet umbrella.