Skip to content
Latchkey

dotnet build: Compile a .NET Project

dotnet build compiles the source in a project or solution and produces assemblies in the output folder.

build is the workhorse. The flags that matter in CI control the configuration, whether it restores first, and how strict it is about warnings.

What it does

dotnet build invokes MSBuild to compile a project or solution and its dependencies, emitting assemblies under bin/<configuration>/<tfm>. It runs an implicit dotnet restore first unless you pass --no-restore.

Common usage

Terminal
dotnet build
dotnet build -c Release
dotnet build MySolution.sln -c Release --no-restore
dotnet build -warnaserror              # treat warnings as errors

Options

FlagWhat it does
-c, --configuration <name>Build configuration, e.g. Debug (default) or Release
--no-restoreSkip the implicit restore (run dotnet restore first)
-f, --framework <tfm>Build only the given target framework
-warnaserrorTreat all warnings as errors
-p:<prop>=<val>Set an MSBuild property, e.g. -p:Version=1.2.3
-v, --verbosity <level>q, m, n, d, diag
-o, --output <dir>Directory for the built artifacts

In CI

Order your steps restore then build --no-restore so the build does not redo the restore. Always pass -c Release for artifacts you ship; the default Debug is slower and unoptimized. Add -warnaserror (or set TreatWarningsAsErrors) once the codebase is clean so new warnings break the build.

Common errors in CI

MSB1003 ("Specify a project or solution file") means the working directory has no or more than one project and you did not name one; pass the path explicitly. NETSDK1045 ("The current .NET SDK does not support targeting <version>") means the installed SDK is older than the project requires; pin the SDK with global.json or upgrade the runner. MSB3027/MSB3021 ("Unable to copy file ... because it is being used by another process") usually means a stale process or a parallel build holding a lock.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →