Skip to content
Latchkey

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 restore and dotnet build --no-restore for cleaner CI caching.
  • Use -c Release and -p:Version= to produce stamped release artifacts.
  • NU1101 is a restore/feed problem; CS0246 is a missing reference.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →