1dotnet build command(1) .NET Core dotnet build command(1)
2
3
4
6 This article applies to: ✓ .NET Core 1.x SDK and later versions
7
9 dotnet build - Builds a project and all of its dependencies.
10
12 dotnet build [<PROJECT>|<SOLUTION>] [-c|--configuration] [-f|--framework] [--force]
13 [--interactive] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo]
14 [-o|--output] [-r|--runtime] [-v|--verbosity] [--version-suffix]
15
16 dotnet build [-h|--help]
17
19 The dotnet build command builds the project and its dependencies into a
20 set of binaries. The binaries include the project’s code in Intermedi‐
21 ate Language (IL) files with a .dll extension. Depending on the
22 project type and settings, other files may be included, such as:
23
24 · An executable that can be used to run the application, if the project
25 type is an executable targeting .NET Core 3.0 or later.
26
27 · Symbol files used for debugging with a .pdb extension.
28
29 · A .deps.json file, which lists the dependencies of the application or
30 library.
31
32 · A .runtimeconfig.json file, which specifies the shared runtime and
33 its version for an application.
34
35 · Other libraries that the project depends on (via project references
36 or NuGet package references).
37
38 For executable projects targeting versions earlier than .NET Core 3.0,
39 library dependencies from NuGet are typically NOT copied to the output
40 folder. They’re resolved from the NuGet global packages folder at run
41 time. With that in mind, the product of dotnet build isn’t ready to be
42 transferred to another machine to run. To create a version of the ap‐
43 plication that can be deployed, you need to publish it (for example,
44 with the dotnet publish command). For more information, see .NET Core
45 Application Deployment.
46
47 For executable projects targeting .NET Core 3.0 and later, library de‐
48 pendencies are copied to the output folder. This means that if there
49 isn’t any other publish-specific logic (such as Web projects have), the
50 build output should be deployable.
51
52 Building requires the project.assets.json file, which lists the depen‐
53 dencies of your application. The file is created when dotnet restore
54 is executed. Without the assets file in place, the tooling can’t re‐
55 solve reference assemblies, which results in errors. With .NET Core
56 1.x SDK, you needed to explicitly run dotnet restore before running
57 dotnet build. Starting with .NET Core 2.0 SDK, dotnet restore runs im‐
58 plicitly when you run dotnet build. If you want to disable implicit
59 restore when running the build command, you can pass the --no-restore
60 option.
61
62 Whether the project is executable or not is determined by the <Output‐
63 Type> property in the project file. The following example shows a
64 project that produces executable code:
65
66 <PropertyGroup>
67 <OutputType>Exe</OutputType>
68 </PropertyGroup>
69
70 To produce a library, omit the <OutputType> property or change its val‐
71 ue to Library. The IL DLL for a library doesn’t contain entry points
72 and can’t be executed.
73
74 MSBuild
75 dotnet build uses MSBuild to build the project, so it supports both
76 parallel and incremental builds. For more information, see Incremental
77 Builds.
78
79 In addition to its options, the dotnet build command accepts MSBuild
80 options, such as -p for setting properties or -l to define a logger.
81 For more information about these options, see the MSBuild Command-Line
82 Reference. Or you can also use the dotnet msbuild command.
83
84 Running dotnet build is equivalent to running dotnet msbuild -restore;
85 however, the default verbosity of the output is different.
86
87 Arguments
88 PROJECT | SOLUTION
89
90 The project or solution file to build. If a project or solution file
91 isn’t specified, MSBuild searches the current working directory for a
92 file that has a file extension that ends in either proj or sln and uses
93 that file.
94
96 · -c|--configuration {Debug|Release}
97
98 Defines the build configuration. The default for most projects is
99 Debug, but you can override the build configuration settings in your
100 project.
101
102 · -f|--framework <FRAMEWORK>
103
104 Compiles for a specific framework. The framework must be defined in
105 the project file.
106
107 · --force
108
109 Forces all dependencies to be resolved even if the last restore was
110 successful. Specifying this flag is the same as deleting the
111 project.assets.json file. Available since .NET Core 2.0 SDK.
112
113 · -h|--help
114
115 Prints out a short help for the command.
116
117 · --interactive
118
119 Allows the command to stop and wait for user input or action. For
120 example, to complete authentication. Available since .NET Core 3.0
121 SDK.
122
123 · --no-dependencies
124
125 Ignores project-to-project (P2P) references and only builds the spec‐
126 ified root project.
127
128 · --no-incremental
129
130 Marks the build as unsafe for incremental build. This flag turns off
131 incremental compilation and forces a clean rebuild of the project’s
132 dependency graph.
133
134 · --no-restore
135
136 Doesn’t execute an implicit restore during build. Available since
137 .NET Core 2.0 SDK.
138
139 · --nologo
140
141 Doesn’t display the startup banner or the copyright message. Avail‐
142 able since .NET Core 3.0 SDK.
143
144 · -o|--output <OUTPUT_DIRECTORY>
145
146 Directory in which to place the built binaries. If not specified,
147 the default path is ./bin/<configuration>/<framework>/. For projects
148 with multiple target frameworks (via the TargetFrameworks property),
149 you also need to define --framework when you specify this option.
150
151 · -r|--runtime <RUNTIME_IDENTIFIER>
152
153 Specifies the target runtime. For a list of Runtime Identifiers
154 (RIDs), see the RID catalog.
155
156 · -v|--verbosity <LEVEL>
157
158 Sets the MSBuild verbosity level. Allowed values are q[uiet], m[ini‐
159 mal], n[ormal], d[etailed], and diag[nostic]. The default is mini‐
160 mal.
161
162 · --version-suffix <VERSION_SUFFIX>
163
164 Sets the value of the $(VersionSuffix) property to use when building
165 the project. This only works if the $(Version) property isn’t set.
166 Then, $(Version) is set to the $(VersionPrefix) combined with the
167 $(VersionSuffix), separated by a dash.
168
170 · Build a project and its dependencies:
171
172 dotnet build
173
174 · Build a project and its dependencies using Release configuration:
175
176 dotnet build --configuration Release
177
178 · Build a project and its dependencies for a specific runtime (in this
179 example, Ubuntu 18.04):
180
181 dotnet build --runtime ubuntu.18.04-x64
182
183 · Build the project and use the specified NuGet package source during
184 the restore operation (.NET Core 2.0 SDK and later versions):
185
186 dotnet build --source c:\packages\mypackages
187
188 · Build the project and set version 1.2.3.4 as a build parameter using
189 the -p MSBuild option:
190
191 dotnet build -p:Version=1.2.3.4
192
193
194
195 dotnet build command(1)