1(1)                                  .NET                                  (1)
2
3
4

dotnet build

6       This article applies to: ✔️ .NET Core 2.x SDK and later versions
7

NAME

9       dotnet build - Builds a project and all of its dependencies.
10

SYNOPSIS

12              dotnet build [<PROJECT>|<SOLUTION>] [-a|--arch <ARCHITECTURE>]
13                  [-c|--configuration <CONFIGURATION>] [-f|--framework <FRAMEWORK>]
14                  [--force] [--interactive] [--no-dependencies] [--no-incremental]
15                  [--no-restore] [--nologo] [--no-self-contained] [--os <OS>]
16                  [-o|--output <OUTPUT_DIRECTORY>] [-r|--runtime <RUNTIME_IDENTIFIER>]
17                  [--self-contained [true|false]] [--source <SOURCE>]
18                  [-v|--verbosity <LEVEL>] [--version-suffix <VERSION_SUFFIX>]
19
20              dotnet build -h|--help
21

DESCRIPTION

23       The dotnet build command builds the project and its dependencies into a
24       set of binaries.  The binaries include the project’s code in Intermedi‐
25       ate  Language  (IL)  files  with  a  .dll  extension.  Depending on the
26       project type and settings, other files may be included, such as:
27
28       • An executable that can be used to run the application, if the project
29         type is an executable targeting .NET Core 3.0 or later.
30
31       • Symbol files used for debugging with a .pdb extension.
32
33       • A .deps.json file, which lists the dependencies of the application or
34         library.
35
36       • A .runtimeconfig.json file, which specifies the  shared  runtime  and
37         its version for an application.
38
39       • Other  libraries  that the project depends on (via project references
40         or NuGet package references).
41
42       For executable projects targeting versions earlier than .NET Core  3.0,
43       library  dependencies from NuGet are typically NOT copied to the output
44       folder.  They’re resolved from the NuGet global packages folder at  run
45       time.  With that in mind, the product of dotnet build isn’t ready to be
46       transferred to another machine to run.  To create a version of the  ap‐
47       plication  that  can  be deployed, you need to publish it (for example,
48       with the dotnet publish command).  For more information, see  .NET  Ap‐
49       plication Deployment.
50
51       For  executable projects targeting .NET Core 3.0 and later, library de‐
52       pendencies are copied to the output folder.  This means that  if  there
53       isn’t any other publish-specific logic (such as Web projects have), the
54       build output should be deployable.
55
56   Implicit restore
57       Building requires the project.assets.json file, which lists the  depen‐
58       dencies  of  your application.  The file is created when dotnet restore
59       is executed.  Without the assets file in place, the tooling  can’t  re‐
60       solve reference assemblies, which results in errors.
61
62       You don’t have to run dotnet restore because it’s run implicitly by all
63       commands that require a restore to occur, such as  dotnet  new,  dotnet
64       build,  dotnet  run,  dotnet test, dotnet publish, and dotnet pack.  To
65       disable implicit restore, use the --no-restore option.
66
67       The dotnet restore command is still useful in certain  scenarios  where
68       explicitly restoring makes sense, such as continuous integration builds
69       in Azure DevOps Services or in build systems that  need  to  explicitly
70       control when the restore occurs.
71
72       For information about how to manage NuGet feeds, see the dotnet restore
73       documentation.
74
75       This command supports the dotnet restore options  when  passed  in  the
76       long form (for example, --source).  Short form options, such as -s, are
77       not supported.
78
79   Executable or library output
80       Whether the project is executable or not is determined by the  <Output‐
81       Type>  property  in  the  project  file.  The following example shows a
82       project that produces executable code:
83
84              <PropertyGroup>
85                <OutputType>Exe</OutputType>
86              </PropertyGroup>
87
88       To produce a library, omit the <OutputType> property or change its val‐
89       ue  to  Library.  The IL DLL for a library doesn’t contain entry points
90       and can’t be executed.
91
92   MSBuild
93       dotnet build uses MSBuild to build the project,  so  it  supports  both
94       parallel and incremental builds.  For more information, see Incremental
95       Builds.
96
97       In addition to its options, the dotnet build  command  accepts  MSBuild
98       options,  such  as  -p for setting properties or -l to define a logger.
99       For more information about these options, see the MSBuild  Command-Line
100       Reference.  Or you can also use the dotnet msbuild command.
101
102              [!NOTE]  When  dotnet  build is run automatically by dotnet run,
103              arguments like -property:property=value aren’t respected.
104
105       Running dotnet build is equivalent to running dotnet msbuild  -restore;
106       however, the default verbosity of the output is different.
107
108   Workload manifest downloads
109       When  you  run  this  command,  it initiates an asynchronous background
110       download of advertising manifests for workloads.  If  the  download  is
111       still running when this command finishes, the download is stopped.  For
112       more information, see Advertising manifests.
113
114   Arguments
115       PROJECT | SOLUTION
116
117       The project or solution file to build.  If a project or  solution  file
118       isn’t  specified,  MSBuild searches the current working directory for a
119       file that has a file extension that ends in either proj or sln and uses
120       that file.
121

OPTIONS

123-a|--arch <ARCHITECTURE>
124
125         Specifies  the  target  architecture.  This is a shorthand syntax for
126         setting the Runtime Identifier (RID), where  the  provided  value  is
127         combined  with  the  default RID.  For example, on a win-x64 machine,
128         specifying --arch x86 sets the RID to win-x86.  If you use  this  op‐
129         tion, don’t use the -r|--runtime option.  Available since .NET 6 Pre‐
130         view 7.
131
132-c|--configuration <CONFIGURATION>
133
134         Defines the build configuration.  The default for  most  projects  is
135         Debug,  but you can override the build configuration settings in your
136         project.
137
138-f|--framework <FRAMEWORK>
139
140         Compiles for a specific framework.  The framework must be defined  in
141         the project file.
142
143--force
144
145         Forces  all  dependencies to be resolved even if the last restore was
146         successful.  Specifying  this  flag  is  the  same  as  deleting  the
147         project.assets.json file.
148
149-?|-h|--help
150
151         Prints out a description of how to use the command.
152
153--interactive
154
155         Allows  the  command  to stop and wait for user input or action.  For
156         example, to complete authentication.  Available since .NET  Core  3.0
157         SDK.
158
159--no-dependencies
160
161         Ignores project-to-project (P2P) references and only builds the spec‐
162         ified root project.
163
164--no-incremental
165
166         Marks the build as unsafe for incremental build.  This flag turns off
167         incremental  compilation  and forces a clean rebuild of the project’s
168         dependency graph.
169
170--no-restore
171
172         Doesn’t execute an implicit restore during build.
173
174--nologo
175
176         Doesn’t display the startup banner or the copyright message.   Avail‐
177         able since .NET Core 3.0 SDK.
178
179--no-self-contained
180
181         Publishes  the  application  as a framework dependent application.  A
182         compatible .NET runtime must be installed on the  target  machine  to
183         run the application.
184
185-o|--output <OUTPUT_DIRECTORY>
186
187         Directory  in  which  to place the built binaries.  If not specified,
188         the default path is ./bin/<configuration>/<framework>/.  For projects
189         with  multiple target frameworks (via the TargetFrameworks property),
190         you also need to define --framework when you specify this option.
191
192--os <OS>
193
194         Specifies the target operating system (OS).  This is a shorthand syn‐
195         tax for setting the Runtime Identifier (RID), where the provided val‐
196         ue is combined with the default RID.  For example, on a  win-x64  ma‐
197         chine,  specifying  --os  os sets the RID to os-x64.  If you use this
198         option, don’t use the -r|--runtime option.  Available  since  .NET  6
199         Preview 7.
200
201-r|--runtime <RUNTIME_IDENTIFIER>
202
203         Specifies  the  target  runtime.   For  a list of Runtime Identifiers
204         (RIDs), see the RID catalog.  If you use this option, use --self-con‐
205         tained or --no-self-contained also.
206
207--self-contained [true|false]
208
209         Publishes  the  .NET  runtime  with  the  application  so the runtime
210         doesn’t need to be installed on the target machine.  The  default  is
211         true if a runtime identifier is specified.
212
213--source <SOURCE>
214
215         The  URI of the NuGet package source to use during the restore opera‐
216         tion.
217
218-v|--verbosity <LEVEL>
219
220         Sets the verbosity level of the command.  Allowed values are q[uiet],
221         m[inimal],  n[ormal],  d[etailed],  and diag[nostic].  The default is
222         minimal.   For  more  information,  see  <xref:Microsoft.Build.Frame‐
223         work.LoggerVerbosity>.
224
225--version-suffix <VERSION_SUFFIX>
226
227         Sets  the value of the $(VersionSuffix) property to use when building
228         the project.  This only works if the $(Version) property  isn’t  set.
229         Then,  $(Version)  is  set  to the $(VersionPrefix) combined with the
230         $(VersionSuffix), separated by a dash.
231

EXAMPLES

233       • Build a project and its dependencies:
234
235                dotnet build
236
237       • Build a project and its dependencies using Release configuration:
238
239                dotnet build --configuration Release
240
241       • Build a project and its dependencies for a specific runtime (in  this
242         example, Ubuntu 18.04):
243
244                dotnet build --runtime ubuntu.18.04-x64
245
246       • Build  the  project and use the specified NuGet package source during
247         the restore operation:
248
249                dotnet build --source c:\packages\mypackages
250
251       • Build the project and set version 1.2.3.4 as a build parameter  using
252         the -p MSBuild option:
253
254                dotnet build -p:Version=1.2.3.4
255
256
257
258                                                                           (1)
Impressum