This article applies to: ✔️ .NET Core 2.x SDK and later versions
dotnet build - Builds a project and all of its dependencies.
dotnet build [<PROJECT>|<SOLUTION>] [-c|--configuration <CONFIGURATION>] [-f|--framework <FRAMEWORK>] [--force] [--interactive] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo] [-o|--output <OUTPUT_DIRECTORY>] [-r|--runtime <RUNTIME_IDENTIFIER>] [--source <SOURCE>] [-v|--verbosity <LEVEL>] [--version-suffix <VERSION_SUFFIX>] dotnet build -h|--help
dotnet build command builds the project and its dependencies into a set of binaries. The binaries include the project's code in Intermediate Language (IL) files with a .dll extension. Depending on the project type and settings, other files may be included, such as:
- An executable that can be used to run the application, if the project type is an executable targeting .NET Core 3.0 or later.
- Symbol files used for debugging with a .pdb extension.
- A .deps.json file, which lists the dependencies of the application or library.
- A .runtimeconfig.json file, which specifies the shared runtime and its version for an application.
- Other libraries that the project depends on (via project references or NuGet package references).
For executable projects targeting versions earlier than .NET Core 3.0, library dependencies from NuGet are typically NOT copied to the output folder. They're resolved from the NuGet global packages folder at run time. With that in mind, the product of
dotnet build isn't ready to be transferred to another machine to run. To create a version of the application that can be deployed, you need to publish it (for example, with the dotnet publish command). For more information, see .NET Core Application Deployment.
For executable projects targeting .NET Core 3.0 and later, library dependencies are copied to the output folder. This means that if there isn't any other publish-specific logic (such as Web projects have), the build output should be deployable.
Building requires the project.assets.json file, which lists the dependencies of your application. The file is created when
dotnet restore is executed. Without the assets file in place, the tooling can't resolve reference assemblies, which results in errors.
You don't have to run
dotnet restore because it's run implicitly by all commands that require a restore to occur, such as
dotnet publish, and
dotnet pack. To disable implicit restore, use the
dotnet restore command is still useful in certain scenarios where explicitly restoring makes sense, such as continuous integration builds in Azure DevOps Services or in build systems that need to explicitly control when the restore occurs.
For information about how to manage NuGet feeds, see the
dotnet restore documentation.
This command supports the
dotnet restore options when passed in the long form (for example,
--source). Short form options, such as
-s, are not supported.
Executable or library output
Whether the project is executable or not is determined by the
<OutputType> property in the project file. The following example shows a project that produces executable code:
<PropertyGroup> <OutputType>Exe</OutputType> </PropertyGroup>
To produce a library, omit the
<OutputType> property or change its value to
Library. The IL DLL for a library doesn't contain entry points and can't be executed.
dotnet build uses MSBuild to build the project, so it supports both parallel and incremental builds. For more information, see Incremental Builds.
In addition to its options, the
dotnet build command accepts MSBuild options, such as
-p for setting properties or
-l to define a logger. For more information about these options, see the MSBuild Command-Line Reference. Or you can also use the dotnet msbuild command.
dotnet build is equivalent to running
dotnet msbuild -restore; however, the default verbosity of the output is different.
PROJECT | SOLUTION
The project or solution file to build. If a project or solution file isn't specified, MSBuild searches the current working directory for a file that has a file extension that ends in either proj or sln and uses that file.
Defines the build configuration. The default for most projects is
Debug, but you can override the build configuration settings in your project.
Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file.
Prints out a short help for the command.
Allows the command to stop and wait for user input or action. For example, to complete authentication. Available since .NET Core 3.0 SDK.
Ignores project-to-project (P2P) references and only builds the specified root project.
Marks the build as unsafe for incremental build. This flag turns off incremental compilation and forces a clean rebuild of the project's dependency graph.
Doesn't execute an implicit restore during build.
Doesn't display the startup banner or the copyright message. Available since .NET Core 3.0 SDK.
Directory in which to place the built binaries. If not specified, the default path is
./bin/<configuration>/<framework>/. For projects with multiple target frameworks (via the
TargetFrameworksproperty), you also need to define
--frameworkwhen you specify this option.
Specifies the target runtime. For a list of Runtime Identifiers (RIDs), see the RID catalog.
The URI of the NuGet package source to use during the restore operation.
Sets the MSBuild verbosity level. Allowed values are
diag[nostic]. The default is
Sets the value of the
$(VersionSuffix)property to use when building the project. This only works if the
$(Version)property isn't set. Then,
$(Version)is set to the
$(VersionPrefix)combined with the
$(VersionSuffix), separated by a dash.
Build a project and its dependencies:
Build a project and its dependencies using Release configuration:
dotnet build --configuration Release
Build a project and its dependencies for a specific runtime (in this example, Ubuntu 18.04):
dotnet build --runtime ubuntu.18.04-x64
Build the project and use the specified NuGet package source during the restore operation (.NET Core 2.0 SDK and later versions):
dotnet build --source c:\packages\mypackages
Build the project and set version 126.96.36.199 as a build parameter using the
dotnet build -p:Version=188.8.131.52