diff --git a/docs/core/tools/dotnet-build.md b/docs/core/tools/dotnet-build.md index 6d35a9bb5a48e..eba12b7237cab 100644 --- a/docs/core/tools/dotnet-build.md +++ b/docs/core/tools/dotnet-build.md @@ -1,8 +1,9 @@ --- title: dotnet build command description: The dotnet build command builds a project and all of its dependencies. -ms.date: 09/24/2025 +ms.date: 05/18/2026 --- + # dotnet build **This article applies to:** ✔️ .NET 6 SDK and later versions @@ -21,7 +22,7 @@ dotnet build [||] [-a|--arch ] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo] [--no-self-contained] [-o|--output ] [--os ] [-p|--property:=] [-r|--runtime ] - [--sc|--self-contained] [--source ] + [--sc|--self-contained] [--source ] [-t|--target:] [--tl:[auto|on|off]] [ --ucr|--use-current-runtime] [-v|--verbosity ] [--version-suffix ] @@ -94,6 +95,7 @@ Running `dotnet build` is equivalent to running `dotnet msbuild -restore`; howev dotnet build -bl:build-log.binlog ``` + - [!INCLUDE [configuration](includes/cli-configuration.md)] - [!INCLUDE [disable-build-servers](includes/cli-disable-build-servers.md)] @@ -155,6 +157,16 @@ Running `dotnet build` is equivalent to running `dotnet msbuild -restore`; howev The URI of the NuGet package source to use during the restore operation. +- **`-t|--target:`** + + Specifies one or more MSBuild targets to run during the build instead of the default target. Specify multiple targets by separating them with a semicolon or comma, or by repeating the option for each target. Corresponds to the MSBuild `-target` option. Common targets include `Build` (default), `Clean`, and `Rebuild`. For more information, see [MSBuild Targets](/visualstudio/msbuild/msbuild-targets). + + ```dotnetcli + dotnet build -t:"Clean;RunTests" + dotnet build -t:Clean -t:GenerateApiClients + dotnet build -t:RunCodeGeneration + ``` + - [!INCLUDE [tl](includes/cli-tl.md)] - [!INCLUDE [use-current-runtime](includes/cli-use-current-runtime.md)] @@ -206,3 +218,15 @@ Running `dotnet build` is equivalent to running `dotnet msbuild -restore`; howev ```dotnetcli dotnet build -p:Version=1.2.3.4 ``` + +- Run the `Clean` target to remove previous build outputs: + + ```dotnetcli + dotnet build -t:Clean + ``` + +- Run the `Clean` target using the equivalent space-separated syntax: + + ```dotnetcli + dotnet build -t Clean + ```