dotnet build Command: Build .NET in CI
dotnet build restores, compiles, and outputs a .NET project or solution.
dotnet build is the .NET SDK command that compiles projects and solutions via MSBuild. In CI it follows dotnet restore (or restores implicitly) and produces assemblies; many pipelines also use dotnet test and dotnet publish around it.
Common flags
-c Release/--configuration Release- build configuration (Debug/Release)-o DIR/--output DIR- output directory for build artifacts-f net8.0/--framework- build a specific target framework--no-restore- skip the implicit restore (after a separate restore step)-p:Name=Value- set an MSBuild property (e.g. version)--verbosity minimal|normal|detailed- control log detail-r linux-x64/--runtime- set the runtime identifier (RID)
Example in CI
Restore once then build in Release without re-restoring, stamping a version:
shell
dotnet restore
dotnet build -c Release --no-restore -p:Version=\${BUILD_VERSION}Common errors in CI
- error NU1101: Unable to find package X - wrong feed or package name (restore failed)
- error CS0246: The type or namespace name 'X' could not be found - missing reference/using
- error NETSDK1045: The current .NET SDK does not support targeting net8.0 - SDK too old
- error MSB1009: Project file does not exist - wrong path or solution filter
Key takeaways
- Split
dotnet restoreanddotnet build --no-restorefor cleaner CI caching. - Use
-c Releaseand-p:Version=to produce stamped release artifacts. - NU1101 is a restore/feed problem; CS0246 is a missing reference.
Related guides
csc Command: Compile C# in CIcsc is the C# compiler. Reference for /out, /target, /reference, /optimize, /langversion, /nowarn, and the C#…
mvn Command: Build Maven Projects in CImvn is the Maven build tool. Reference for clean, install, verify, -B, -DskipTests, -P, -pl, and the Maven CI…
go build Command: Compile Go in CIgo build compiles Go packages. Reference for -o, -ldflags, -tags, -race, GOOS/GOARCH cross-compilation, and t…