LinuxCommandLibrary

dotnet-build

Build .NET projects and dependencies

TLDR

Compile the project or solution in the current directory

$ dotnet build
copy

Compile a .NET project or solution in debug mode
$ dotnet build [path/to/project_or_solution]
copy

Compile in release mode
$ dotnet build [[-c|--configuration]] [Release]
copy

Compile without restoring dependencies
$ dotnet build --no-restore
copy

Compile with a specific verbosity level
$ dotnet build [[-v|--verbosity]] [quiet|minimal|normal|detailed|diagnostic]
copy

Compile for a specific runtime
$ dotnet build [[-r|--runtime]] [runtime_identifier]
copy

Specify the output directory
$ dotnet build [[-o|--output]] [path/to/directory]
copy

SYNOPSIS

dotnet build [PROJECT|SOLUTION] [options]

PARAMETERS

-c|--configuration <CONFIGURATION>
    Configuration to use during build (e.g., Debug or Release).

-f|--framework <FRAMEWORK>
    Builds for a specific runtime framework (e.g., net8.0).

-o|--output <DIR>
    Directory for build output files.

--no-incremental
    Disables incremental build processing.

--no-restore
    Skips package restore step.

-r|--runtime <RUNTIME_IDENTIFIER>
    Target runtime (e.g., linux-x64).

-v|--verbosity <LEVEL>
    Sets verbosity: quiet, minimal, normal, detailed, or diagnostic.

--no-dependencies
    Ignores project-to-project references, builds only specified project.

-p:<NAME>=<VALUE>
    Sets MSBuild property (e.g., -p:Version=1.0).

-h|--help
    Shows help and options.

DESCRIPTION

dotnet build is a core command in the .NET CLI used to compile a .NET project and its dependencies into a set of output binaries, typically DLLs or executables in Intermediate Language (IL) format runnable on the .NET runtime.

It automatically restores NuGet packages if necessary (unless disabled), performs incremental builds to speed up recompilation by reusing unchanged outputs, and supports multiple target frameworks, configurations like Debug or Release, and platforms.

The command processes project files (.csproj or solutions .sln), invokes MSBuild under the hood for the actual compilation, and places outputs in directories like bin/Debug/net8.0/. It's essential for development workflows, CI/CD pipelines, and preparing apps for deployment.

Customization via MSBuild properties (-p:Key=Value) allows fine-tuning, such as setting version numbers or enabling trimming. Verbosity levels help debug build issues, from quiet to diagnostic logs.

For cross-platform development on Linux, it targets Linux runtimes seamlessly, producing self-contained or framework-dependent apps. Always ensure the .NET SDK is installed via dotnet --version. (187 words)

CAVEATS

Requires .NET SDK installed; outputs to bin/ by default; may fail if project targets unsupported frameworks or missing dependencies.
Incremental builds can cache incorrectly if source changes externally.

EXAMPLES

dotnet build - Builds current directory project.
dotnet build MyApp.csproj -c Release -o ./out - Release build to custom output.
dotnet build Solution.sln --framework net8.0 - Builds solution for specific framework.

HISTORY

Introduced with .NET Core SDK 1.0 in 2016 as part of cross-platform .NET shift from .NET Framework.
Evolved through .NET Core 2.x/3.x; unified with .NET 5+ (2020) into single SDK supporting all platforms.

SEE ALSO

dotnet restore, dotnet run, dotnet publish, msbuild(1)

Copied to clipboard