Command-Line Reference
|
This section documents MSBuild 18.9, the .NET SDK 10.0.402 (with its This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production. The C# Reference bibliography lists the reference material consulted while preparing these pages. |
msbuild.exe and dotnet msbuild take the same command line: an optional project or solution file and a list of
switches. The dotnet build, test, pack, publish, restore, clean and run commands also accept every MSBuild
switch after their own options. This page lists every switch of MSBuild 18.9 (as printed by dotnet msbuild -help
from .NET SDK 10.0.402) grouped by purpose, with the short form and the dotnet equivalent where one exists.
Syntax
msbuild.exe [options] [project file | directory]
dotnet msbuild [options] [project file | directory]
-
Switches start with
-or/(-t:Build,/t:Build; on Linux and macOS use-) and--is accepted too (--property:); values follow a colon. Switch names are case-insensitive. -
Without a file, MSBuild uses the single project or solution file in the current directory (
MSB1011if it cannot decide; see Solutions and .slnx). -
@file.rspreads switches from a response file;Directory.Build.rspandMSBuild.rspare read automatically. -
Exit code 0 means success, 1 means the build (or the command line) failed.
dotnet msbuild missing.proj -nologo; echo "exit=$?"
MSBUILD : error MSB1009: Project file does not exist.
Switch: missing.proj
exit=1
Targets and properties
| Switch | Effect | dotnet form |
|---|---|---|
|
Build these targets (otherwise |
|
|
Set a global property (overrides the project; several with |
|
|
Run |
implicit in |
|
A global property for the restore phase only. |
same |
|
Ignore files with these extensions when looking for the project to build. |
same |
|
Legacy toolset selection. |
— |
Parallelism
| Switch | Effect |
|---|---|
|
Use up to |
|
(MSBuild 18.6+) build projects in parallel inside one process; tasks not marked multithreadable run in a task host. Listed only in the second copy of the reference’s switch table. |
|
Keep worker nodes alive after the build (default |
|
Run at low process priority. |
Graph builds and caches
| Switch | Effect |
|---|---|
|
Build the static project graph from |
|
Forbid a project from building targets of projects it did not declare as references. |
|
Read/write build results from/to cache files (implies |
Evaluation queries
| Switch | Effect |
|---|---|
|
(17.8+) Print evaluated values (or, with |
|
Write the |
|
Ask whether a named MSBuild feature is |
dotnet msbuild tasks.proj -getProperty:OutDir -getResultOutputFile:outdir.txt
cat outdir.txt
dotnet msbuild -featureAvailability:TerminalLogger
~/tasks/out/
Undefined
(Undefined means the name is unknown to the checker; the feature names are not documented.)
Output, inspection and response files
| Switch | Effect |
|---|---|
|
Write the project with every import inlined. |
|
List the project’s targets. |
|
Console verbosity: quiet, minimal, normal, detailed, diagnostic. |
|
Version, help, banner. |
|
Ignore |
|
Read switches from a response file. |
|
Validate the project against the MSBuild schema — |
|
(Experimental) Fail if any incremental target or task is not up to date — a check that a build is fully incremental. Not in the online reference. |
|
Profile evaluation; |
|
Print node usage and per-project timing at the end. |
-question makes a build that would do work fail instead. On the journal generator from
Incremental Builds and Batching,
after touching one journal, and again after a real build:
touch journals/feb.ledger.csv
dotnet msbuild Journals.csproj -question -tl:off -v:m; echo "exit=$?"
dotnet build Journals.csproj
dotnet msbuild Journals.csproj -question -tl:off -v:m; echo "exit=$?"
MSBUILD : error : Building target "GenerateJournalClasses" partially, because some output files are out of date with respect to their input files. [~/journals/Journals.csproj]
exit=1
…
exit=0
A response file and the target listing:
printf -- '-nologo\n-v:m\n-t:Archive\n' > archive.rsp
dotnet msbuild tasks.proj @archive.rsp
dotnet msbuild tasks.proj -ts:targets.txt -nologo && cat targets.txt
Zipping directory "~/tasks/out/journals" to "~/tasks/out/journals.zip".
Archived to journals.zip, deleted summary.txt
Tour
Archive
Source: MSBuild command-line reference.
Logging
| Switch | Effect |
|---|---|
|
Write a binary log (default |
|
(17.8+) The Terminal Logger; |
|
|
|
Write text logs ( |
|
One log file per node. |
|
Attach a custom logger. |
|
A central logger with a forwarding logger in each node. |
|
Disable the console logger. |
Warnings and errors
| Switch | Effect |
|---|---|
|
Treat all warnings, or the listed codes, as errors. |
|
(17.0+) Exclude codes from a global |
|
Downgrade codes to low-importance messages. |
dotnet msbuild tasks.proj -nologo -v:q -warnAsError:LL1001; echo "exit=$?"
dotnet msbuild tasks.proj -nologo -v:m -warnAsMessage:LL1001 | grep -c "warning LL1001"
~/tasks/tasks.proj(43,5): error LL1001: Ledger warning example
exit=1
0
The project-level equivalents are the MSBuildTreatWarningsAsErrors, MSBuildWarningsAsErrors,
MSBuildWarningsAsMessages and MSBuildWarningsNotAsErrors properties (and the compiler’s TreatWarningsAsErrors,
WarningsAsErrors, NoWarn, which affect only compiler and NuGet diagnostics).
Source: MSBuild command-line reference.
Other switches
| Switch | Effect |
|---|---|
|
Allow tasks to interact with the user (credential prompts during restore). |
|
Enable BuildCheck analyzers (.NET 9 / MSBuild 17.12+, experimental). It appears in |
Gaps in the official reference
On 2026-10-23 the MSBuild command-line reference page contained its switch table twice; the second copy adds
-multiThreaded/-mt. Neither copy lists -check, -question, -profileEvaluation, -getResultOutputFile,
-featureAvailability or -terminalLoggerParameters, all of which dotnet msbuild -help prints for MSBuild 18.9.
Treat msbuild -help as the list for the version you run.
Common mistakes
-
Forgetting
-restorewithdotnet msbuild—NETSDK1004on a fresh clone. -
A
-p:meant for one project applied to a whole solution — global properties flow to every project. -
Comma instead of semicolon between property values or targets.
-
Shell quoting of
;and$— quote the whole switch in Unix shells:'-p:DefineConstants=A;B'. -
Relying on the console output in scripts — use
-getProperty/-getItemor a binary log.