msbuild: Build Solutions with /p /m /t in CI
msbuild compiles a solution or project; /p: sets properties like Configuration, /m enables parallel builds, and /t: picks targets such as Restore;Build.
msbuild is the engine behind .NET Framework and many C++ builds on Windows. The property, parallel, and target switches are what you tune in CI for correctness and speed.
What it does
msbuild evaluates an MSBuild project (or .sln) and executes the requested targets. /p: passes build properties, /t: selects which targets run, and /m[:n] builds independent projects in parallel across CPUs.
Common usage
msbuild MyApp.sln ^
/p:Configuration=Release /p:Platform="Any CPU" ^
/t:Restore;Build ^
/m ^
/verbosity:minimal
# binary log for debugging a CI-only failure
msbuild MyApp.sln /p:Configuration=Release /bl:msbuild.binlogOptions
| Switch | What it does |
|---|---|
| /p:Name=Value | Set a property, e.g. /p:Configuration=Release |
| /t:Target[;Target] | Run specific targets, e.g. /t:Restore;Build |
| /m[:n] | Build in parallel (n = max processes; bare /m uses all cores) |
| /restore | Run an implicit Restore before the build |
| /verbosity:<level> | q[uiet], m[inimal], n[ormal], d[etailed], diag |
| /bl[:file] | Write a binary log for offline diagnosis |
In CI
Add /m to parallelize across the runner's cores, and capture /bl so a CI-only failure can be opened in the MSBuild Structured Log Viewer locally. Put quoted values like /p:Platform="Any CPU" carefully; the space requires quotes.
Common errors in CI
"error MSB3073: The command ... exited with code 1" is an Exec/post-build script failing, not msbuild itself; read the inner command. "error MSB4126: The specified solution configuration ... is invalid" usually means a Platform mismatch (the sln has "Any CPU" but you passed "AnyCPU" without the space). "MSB1009: Project file does not exist" means a wrong path or that you are in the wrong working directory. "The reference assemblies for .NETFramework,Version=vX were not found" means the targeting pack is not installed on the runner.