1dotnet-publish(1) .NET Documentation dotnet-publish(1)
2
3
4
6 This article applies to: ✔️ .NET Core 3.1 SDK and later versions
7
9 dotnet-publish - Publishes the application and its dependencies to a
10 folder for deployment to a hosting system.
11
13 dotnet publish [<PROJECT>|<SOLUTION>] [-a|--arch <ARCHITECTURE>]
14 [-c|--configuration <CONFIGURATION>]
15 [-f|--framework <FRAMEWORK>] [--force] [--interactive]
16 [--manifest <PATH_TO_MANIFEST_FILE>] [--no-build] [--no-dependencies]
17 [--no-restore] [--nologo] [-o|--output <OUTPUT_DIRECTORY>]
18 [--os <OS>] [-r|--runtime <RUNTIME_IDENTIFIER>]
19 [--sc|--self-contained [true|false]] [--no-self-contained]
20 [-s|--source <SOURCE>] [--use-current-runtime, --ucr [true|false]]
21 [-v|--verbosity <LEVEL>] [--version-suffix <VERSION_SUFFIX>]
22
23 dotnet publish -h|--help
24
26 dotnet publish compiles the application, reads through its dependencies
27 specified in the project file, and publishes the resulting set of files
28 to a directory. The output includes the following assets:
29
30 • Intermediate Language (IL) code in an assembly with a dll extension.
31
32 • A .deps.json file that includes all of the dependencies of the
33 project.
34
35 • A .runtimeconfig.json file that specifies the shared runtime that the
36 application expects, as well as other configuration options for the
37 runtime (for example, garbage collection type).
38
39 • The application’s dependencies, which are copied from the NuGet cache
40 into the output folder.
41
42 The dotnet publish command’s output is ready for deployment to a host‐
43 ing system (for example, a server, PC, Mac, laptop) for execution.
44 It’s the only officially supported way to prepare the application for
45 deployment. Depending on the type of deployment that the project spec‐
46 ifies, the hosting system may or may not have the .NET shared runtime
47 installed on it. For more information, see Publish .NET apps with the
48 .NET CLI.
49
50 Implicit restore
51 You don’t have to run dotnet restore because it’s run implicitly by all
52 commands that require a restore to occur, such as dotnet new, dotnet
53 build, dotnet run, dotnet test, dotnet publish, and dotnet pack. To
54 disable implicit restore, use the --no-restore option.
55
56 The dotnet restore command is still useful in certain scenarios where
57 explicitly restoring makes sense, such as continuous integration builds
58 in Azure DevOps Services or in build systems that need to explicitly
59 control when the restore occurs.
60
61 For information about how to manage NuGet feeds, see the dotnet restore
62 documentation.
63
64 MSBuild
65 The dotnet publish command calls MSBuild, which invokes the Publish
66 target. If the IsPublishable property is set to false for a particular
67 project, the Publish target can’t be invoked, and the dotnet publish
68 command only runs the implicit dotnet restore on the project.
69
70 Any parameters passed to dotnet publish are passed to MSBuild. The -c
71 and -o parameters map to MSBuild’s Configuration and PublishDir proper‐
72 ties, respectively.
73
74 The dotnet publish command accepts MSBuild options, such as -p for set‐
75 ting properties and -l to define a logger. For example, you can set an
76 MSBuild property by using the format: -p:<NAME>=<VALUE>.
77
78 You can also set publish-related properties by referring to a .pubxml
79 file. For example:
80
81 dotnet publish -p:PublishProfile=FolderProfile
82
83 The preceding example uses the FolderProfile.pubxml file that is found
84 in the <project_folder>/Properties/PublishProfiles folder. If you
85 specify a path and file extension when setting the PublishProfile prop‐
86 erty, they are ignored. MSBuild by default looks in the Proper‐
87 ties/PublishProfiles folder and assumes the pubxml file extension. To
88 specify the path and filename including extension, set the PublishPro‐
89 fileFullPath property instead of the PublishProfile property.
90
91 The following MSBuild properties change the output of dotnet publish.
92
93 • PublishReadyToRun
94
95 Compiles application assemblies as ReadyToRun (R2R) format. R2R is a
96 form of ahead-of-time (AOT) compilation. For more information, see
97 ReadyToRun images.
98
99 To see warnings about missing dependencies that could cause runtime
100 failures, use PublishReadyToRunShowWarnings=true.
101
102 We recommend that you specify PublishReadyToRun in a publish profile
103 rather than on the command line.
104
105 • PublishSingleFile
106
107 Packages the app into a platform-specific single-file executable.
108 For more information about single-file publishing, see the single-
109 file bundler design document (https://github.com/dotnet/de‐
110 signs/blob/main/accepted/2020/single-file/design.md).
111
112 We recommend that you specify this option in the project file rather
113 than on the command line.
114
115 • PublishTrimmed
116
117 Trims unused libraries to reduce the deployment size of an app when
118 publishing a self-contained executable. For more information, see
119 Trim self-contained deployments and executables. Available since
120 .NET 6 SDK.
121
122 We recommend that you specify this option in the project file rather
123 than on the command line.
124
125 For more information, see the following resources:
126
127 • MSBuild command-line reference
128
129 • Visual Studio publish profiles (.pubxml) for ASP.NET Core app deploy‐
130 ment
131
132 • dotnet msbuild
133
134 Workload manifest downloads
135 When you run this command, it initiates an asynchronous background
136 download of advertising manifests for workloads. If the download is
137 still running when this command finishes, the download is stopped. For
138 more information, see Advertising manifests.
139
141 • PROJECT|SOLUTION
142
143 The project or solution to publish.
144
145 • PROJECT is the path and filename of a C#, F#, or Visual Basic
146 project file, or the path to a directory that contains a C#, F#, or
147 Visual Basic project file. If the directory is not specified, it
148 defaults to the current directory.
149
150 • SOLUTION is the path and filename of a solution file (.sln exten‐
151 sion), or the path to a directory that contains a solution file.
152 If the directory is not specified, it defaults to the current di‐
153 rectory.
154
156 • -a|--arch <ARCHITECTURE>
157
158 Specifies the target architecture. This is a shorthand syntax for
159 setting the Runtime Identifier (RID), where the provided value is
160 combined with the default RID. For example, on a win-x64 machine,
161 specifying --arch x86 sets the RID to win-x86. If you use this op‐
162 tion, don’t use the -r|--runtime option. Available since .NET 6 Pre‐
163 view 7.
164
165 • -c|--configuration <CONFIGURATION>
166
167 Defines the build configuration. The default for most projects is
168 Debug, but you can override the build configuration settings in your
169 project.
170
171 • -f|--framework <FRAMEWORK>
172
173 Publishes the application for the specified target framework. You
174 must specify the target framework in the project file.
175
176 • --force
177
178 Forces all dependencies to be resolved even if the last restore was
179 successful. Specifying this flag is the same as deleting the
180 project.assets.json file.
181
182 • -?|-h|--help
183
184 Prints out a description of how to use the command.
185
186 • --interactive
187
188 Allows the command to stop and wait for user input or action. For
189 example, to complete authentication. Available since .NET Core 3.0
190 SDK.
191
192 • --manifest <PATH_TO_MANIFEST_FILE>
193
194 Specifies one or several target manifests to use to trim the set of
195 packages published with the app. The manifest file is part of the
196 output of the dotnet store command. To specify multiple manifests,
197 add a --manifest option for each manifest.
198
199 • --no-build
200
201 Doesn’t build the project before publishing. It also implicitly sets
202 the --no-restore flag.
203
204 • --no-dependencies
205
206 Ignores project-to-project references and only restores the root
207 project.
208
209 • --nologo
210
211 Doesn’t display the startup banner or the copyright message.
212
213 • --no-restore
214
215 Doesn’t execute an implicit restore when running the command.
216
217 • -o|--output <OUTPUT_DIRECTORY>
218
219 Specifies the path for the output directory.
220
221 If not specified, it defaults to [project_file_folder]/bin/[configu‐
222 ration]/[framework]/publish/ for a framework-dependent executable and
223 cross-platform binaries. It defaults to [project_file_fold‐
224 er]/bin/[configuration]/[framework]/[runtime]/publish/ for a self-
225 contained executable.
226
227 In a web project, if the output folder is in the project folder, suc‐
228 cessive dotnet publish commands result in nested output folders. For
229 example, if the project folder is myproject, and the publish output
230 folder is myproject/publish, and you run dotnet publish twice, the
231 second run puts content files such as .config and .json files in
232 myproject/publish/publish. To avoid nesting publish folders, specify
233 a publish folder that is not directly under the project folder, or
234 exclude the publish folder from the project. To exclude a publish
235 folder named publishoutput, add the following element to a Property‐
236 Group element in the .csproj file:
237
238 <DefaultItemExcludes>$(DefaultItemExcludes);publishoutput**</DefaultItemExcludes>
239
240 • .NET Core 3.x SDK and later
241
242 If you specify a relative path when publishing a project, the gen‐
243 erated output directory is relative to the current working directo‐
244 ry, not to the project file location.
245
246 If you specify a relative path when publishing a solution, all out‐
247 put for all projects goes into the specified folder relative to the
248 current working directory. To make publish output go to separate
249 folders for each project, specify a relative path by using the ms‐
250 build PublishDir property instead of the --output option. For ex‐
251 ample, dotnet publish -p:PublishDir=.\publish sends publish output
252 for each project to a publish folder under the folder that contains
253 the project file.
254
255 • .NET Core 2.x SDK
256
257 If you specify a relative path when publishing a project, the gen‐
258 erated output directory is relative to the project file location,
259 not to the current working directory.
260
261 If you specify a relative path when publishing a solution, each
262 project’s output goes into a separate folder relative to the
263 project file location. If you specify an absolute path when pub‐
264 lishing a solution, all publish output for all projects goes into
265 the specified folder.
266
267 • --os <OS>
268
269 Specifies the target operating system (OS). This is a shorthand syn‐
270 tax for setting the Runtime Identifier (RID), where the provided val‐
271 ue is combined with the default RID. For example, on a win-x64 ma‐
272 chine, specifying --os linux sets the RID to linux-x64. If you use
273 this option, don’t use the -r|--runtime option. Available since .NET
274 6.
275
276 • --sc|--self-contained [true|false]
277
278 Publishes the .NET runtime with your application so the runtime
279 doesn’t need to be installed on the target machine. Default is true
280 if a runtime identifier is specified and the project is an executable
281 project (not a library project). For more information, see .NET ap‐
282 plication publishing and Publish .NET apps with the .NET CLI.
283
284 If this option is used without specifying true or false, the default
285 is true. In that case, don’t put the solution or project argument
286 immediately after --self-contained, because true or false is expected
287 in that position.
288
289 • --no-self-contained
290
291 Equivalent to --self-contained false.
292
293 • --source <SOURCE>
294
295 The URI of the NuGet package source to use during the restore opera‐
296 tion.
297
298 • -r|--runtime <RUNTIME_IDENTIFIER>
299
300 Publishes the application for a given runtime. For a list of Runtime
301 Identifiers (RIDs), see the RID catalog. For more information, see
302 .NET application publishing and Publish .NET apps with the .NET CLI.
303 If you use this option, use --self-contained or --no-self-contained
304 also.
305
306 • -v|--verbosity <LEVEL>
307
308 Sets the verbosity level of the command. Allowed values are q[uiet],
309 m[inimal], n[ormal], d[etailed], and diag[nostic]. The default is
310 minimal. For more information, see <xref:Microsoft.Build.Frame‐
311 work.LoggerVerbosity>.
312
313 • --use-current-runtime, --ucr [true|false]
314
315 Sets the RuntimeIdentifier to a platform portable RuntimeIdentifier
316 based on the one of your machine. This happens implicitly with prop‐
317 erties that require a RuntimeIdentifier, such as SelfContained, Pub‐
318 lishAot, PublishSelfContained, PublishSingleFile, and PublishReady‐
319 ToRun. If the property is set to false, that implicit resolution
320 will no longer occur.
321
322 • --version-suffix <VERSION_SUFFIX>
323
324 Defines the version suffix to replace the asterisk (*) in the version
325 field of the project file.
326
328 • Create a framework-dependent cross-platform binary for the project in
329 the current directory:
330
331 dotnet publish
332
333 Starting with .NET Core 3.0 SDK, this example also creates a frame‐
334 work-dependent executable for the current platform.
335
336 • Create a self-contained executable for the project in the current di‐
337 rectory, for a specific runtime:
338
339 dotnet publish --runtime osx.10.11-x64
340
341 The RID must be in the project file.
342
343 • Create a framework-dependent executable for the project in the cur‐
344 rent directory, for a specific platform:
345
346 dotnet publish --runtime osx.10.11-x64 --self-contained false
347
348 The RID must be in the project file. This example applies to .NET
349 Core 3.0 SDK and later versions.
350
351 • Publish the project in the current directory, for a specific runtime
352 and target framework:
353
354 dotnet publish --framework netcoreapp3.1 --runtime osx.10.11-x64
355
356 • Publish the specified project file:
357
358 dotnet publish ~/projects/app1/app1.csproj
359
360 • Publish the current application but don’t restore project-to-project
361 (P2P) references, just the root project during the restore operation:
362
363 dotnet publish --no-dependencies
364
366 • .NET application publishing overview
367
368 • Publish .NET apps with the .NET CLI
369
370 • Target frameworks
371
372 • Runtime Identifier (RID) catalog
373
374 • Working with macOS Catalina Notarization
375
376 • Directory structure of a published application
377
378 • MSBuild command-line reference
379
380 • Visual Studio publish profiles (.pubxml) for ASP.NET Core app deploy‐
381 ment
382
383 • dotnet msbuild
384
385 • ILLInk.Tasks
386
387
388
389 2022-10-24 dotnet-publish(1)