You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*`PublishSingleFile` - Enables single-file publishing. Also enables single-file warnings during `dotnet build`.
127
127
*`SelfContained` - Determines whether the app will be self-contained or framework-dependent.
128
-
*`RuntimeIdentifier` - Specifies the [OS and CPU type](../rid-catalog.md) you are targeting.
128
+
*`RuntimeIdentifier` - Specifies the [OS and CPU type](../rid-catalog.md) you are targeting. Also sets `<SelfContained>true</SelfContained>` by default.
129
129
*`PublishTrimmed` - Enables use of [assembly trimming](trim-self-contained.md), which is only supported for self-contained apps.
@@ -136,18 +136,29 @@ These properties have the following functions:
136
136
137
137
## Publish a single file app - CLI
138
138
139
-
Publish a single file application using the [dotnet publish](../tools/dotnet-publish.md) command. When you publish your app, set the following properties:
139
+
Publish a single file application using the [dotnet publish](../tools/dotnet-publish.md) command.
140
140
141
-
- Publish for a specific runtime: `-r win-x64`
142
-
- Publish as a single-file: `-p:PublishSingleFile=true`
141
+
01. Add `<PublishSingleFile>true</PublishSingleFile>` to your project file.
143
142
144
-
The following example publishes an app for Windows as a self-contained single file application.
143
+
This will produce a single-file app on self-contained publish. It also shows single-file compatibility warnings during build.
`<PublishSingleFile>` should be set in the project file to enable single-file analysis during build, but it is also possible to pass these options as `dotnet publish` arguments:
@@ -159,6 +170,8 @@ For more information, see [Publish .NET Core apps with .NET Core CLI](deploy-wit
159
170
160
171
Visual Studio creates reusable publishing profiles that control how your application is published.
161
172
173
+
01. Add `<PublishSingleFile>true</PublishSingleFile>` to your project file.
174
+
162
175
01. On the **Solution Explorer** pane, right-click on the project you want to publish. Select **Publish**.
163
176
164
177
:::image type="content" source="media/single-file/visual-studio-solution-explorer.png" alt-text="Solution Explorer with a right-click menu highlighting the Publish option.":::
Copy file name to clipboardExpand all lines: docs/core/deploying/trim-self-contained.md
+23-12Lines changed: 23 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -38,37 +38,48 @@ When the code is indirectly referencing an assembly through reflection, you can
38
38
39
39
## Trim your app - CLI
40
40
41
-
Trim your application using the [dotnet publish](../tools/dotnet-publish.md) command. When you publish your app, set the following properties:
41
+
Trim your application using the [dotnet publish](../tools/dotnet-publish.md) command.
42
42
43
-
- Publish as a self-contained app for a specific runtime: `-r win-x64`
44
-
- Enable trimming: `/p:PublishTrimmed=true`
43
+
01. Add `<PublishTrimmed>true</PublishTrimmed>` to your project file.
45
44
46
-
The following example publishes an app for Windows as self-contained and trims the output.
45
+
This will produce a trimmed app on self-contained publish. It also turns off trim-incompatible features and shows trim compatibility warnings during build.
47
46
48
-
```xml
49
-
<PropertyGroup>
50
-
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
51
-
<PublishTrimmed>true</PublishTrimmed>
52
-
</PropertyGroup>
53
-
```
47
+
```xml
48
+
<PropertyGroup>
49
+
<PublishTrimmed>true</PublishTrimmed>
50
+
</PropertyGroup>
51
+
```
52
+
53
+
01. Publish a self-contained app for a specific runtime identifier using `dotnet publish -r <RID>`
54
54
55
-
The following example publishes an app in the aggressive trim mode where unused code within assemblies will be trimmed and trimmer warnings enabled.
55
+
The following example publishes the app for Windows as trimmed self-contained application.
56
+
57
+
`dotnet publish -r win-x64`
58
+
59
+
Note that trimming is only supported for self-contained apps.
60
+
61
+
The following example configures an app in the aggressive trim mode where unused code within assemblies will be trimmed and trimmer warnings enabled.
`<PublishTrimmed>` should be set in the project file so that trim-incompatible features are disabled during `dotnet build`, but it is also possible to pass these options as `dotnet publish` arguments:
For more information, see [Publish .NET Core apps with .NET Core CLI](deploy-with-cli.md).
67
76
68
77
## Trim your app - Visual Studio
69
78
70
79
Visual Studio creates reusable publishing profiles that control how your application is published.
71
80
81
+
01. Add `<PublishTrimmed>true</PublishTrimmed>` to your project file.
82
+
72
83
01. On the **Solution Explorer** pane, right-click on the project you want to publish. Select **Publish...**.
73
84
74
85
:::image type="content" source="media/trim-self-contained/visual-studio-solution-explorer.png" alt-text="Solution Explorer with a right-click menu highlighting the Publish option.":::
Copy file name to clipboardExpand all lines: docs/core/deploying/trimming-options.md
+46-3Lines changed: 46 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -16,13 +16,17 @@ Trimming with `PublishTrimmed` was introduced in .NET Core 3.0. The other option
16
16
17
17
-`<PublishTrimmed>true</PublishTrimmed>`
18
18
19
-
Enable trimming during publish, with the default settings defined by the SDK.
19
+
Enable trimming during publish. This also turns off trim-incompatible features and enables [trim analysis](#roslyn-analyzer) during build.
20
20
21
-
This will trim any assemblies which have been configured for trimming. With `Microsoft.NET.Sdk` in .NET 6, this includes the any assemblies with `[AssemblyMetadata("IsTrimmable", "True")]`, which is the case for framework assemblies. In .NET 5, framework assemblies from the netcoreapp runtime pack are configured for trimming via `<IsTrimmable>` MSBuild metadata. Other SDKs may define different defaults.
21
+
Place this in the project file to ensure that the setting applies during `dotnet build`, not just `dotnet publish`.
22
+
23
+
This will trim any assemblies that have been configured for trimming. With `Microsoft.NET.Sdk` in .NET 6, this includes the any assemblies with `[AssemblyMetadata("IsTrimmable", "True")]`, which is the case for framework assemblies. In .NET 5, framework assemblies from the netcoreapp runtime pack are configured for trimming via `<IsTrimmable>` MSBuild metadata. Other SDKs may define different defaults.
24
+
25
+
Starting in .NET 6, this setting also enables the trim compatibility [Roslyn analyzer](#roslyn-analyzer), and disables [features that are incompatible with trimming](#framework-features-disabled-when-trimming).
22
26
23
27
## Trimming granularity
24
28
25
-
The following granularity settings control how aggressively unused IL is discarded. This can be set as a property affecting all trimmer input assemblies, or as metadata on an [individual assembly](#trimmed-assemblies) which overrides the property setting.
29
+
The following granularity settings control how aggressively unused IL is discarded. This can be set as a property affecting all trimmer input assemblies, or as metadata on an [individual assembly](#trimmed-assemblies), which overrides the property setting.
26
30
27
31
-`<TrimMode>link</TrimMode>`
28
32
@@ -173,6 +177,10 @@ The SDK also makes it possible to disable debugger support using the property `D
173
177
174
178
Several feature areas of the framework libraries come with linker directives that make it possible to remove the code for disabled features.
Remove code that creates autorelease pools on supported platforms. See [AutoreleasePool for managed threads](../run-time-config/threading.md#autoreleasepool-for-managed-threads). This is the default for the .NET SDK.
183
+
176
184
-`<DebuggerSupport>false</DebuggerSupport>`
177
185
178
186
Remove code that enables better debugging experiences. This will also [remove symbols](#remove-symbols).
@@ -197,8 +205,43 @@ Several feature areas of the framework libraries come with linker directives tha
197
205
198
206
Remove globalization specific code and data. For more information, see [Invariant mode](../run-time-config/globalization.md#invariant-mode).
Strip exception messages for `System.*` assemblies. When an exception is thrown from a `System.*` assembly, the message will be a simplified resource ID instead of the full message.
203
219
204
220
These properties will cause the related code to be trimmed and will also disable features via the [runtimeconfig](../run-time-config/index.md) file. For more information about these properties, including the corresponding runtimeconfig options, see [feature switches](https://github.com/dotnet/runtime/blob/main/docs/workflow/trimming/feature-switches.md). Some SDKs may have default values for these properties.
221
+
222
+
## Framework features disabled when trimming
223
+
224
+
The following features are incompatible with trimming because they require code that is not statically referenced. These are disabled by default in trimmed apps.
225
+
226
+
> [!WARNING]
227
+
> Enable these features at your own risk. They are likely to break trimmed apps without extra work to preserve the dynamically referenced code.
228
+
229
+
-`<BuiltInComInteropSupport>`
230
+
231
+
Built-in COM support is disabled.
232
+
233
+
-`<CustomResourceTypesSupport>`
234
+
235
+
Use of custom resource types is not supported. ResourceManager code paths that use reflection for custom resource types is trimmed.
[`DesigntimeLicenceContextSerializer`](https://docs.microsoft.com/dotnet/api/system.componentmodel.design.designtimelicensecontextserializer?view=net-5.0) use of BinaryFormatter serialization is disabled.
244
+
245
+
-`<StartupHookSupport>`
246
+
247
+
Running code before `Main` with `DOTNET_STARTUP_HOOKS` is not supported. For more information, see [host startup hook](https://github.com/dotnet/runtime/blob/main/docs/design/features/host-startup-hook.md).
The preceding example uses the *FolderProfile.pubxml* file that is found in the *\<project_folder>/Properties/PublishProfiles* folder. If you specify a path and file extension when setting the `PublishProfile` property, they are ignored. MSBuild by default looks in the *Properties/PublishProfiles* folder and assumes the *pubxml* file extension. To specify the path and filename including extension, set the `PublishProfileFullPath` property instead of the `PublishProfile` property.
59
58
59
+
The following MSBuild properties change the output of `dotnet publish`.
60
+
61
+
-`PublishReadyToRun`
62
+
63
+
Compiles application assemblies as ReadyToRun (R2R) format. R2R is a form of ahead-of-time (AOT) compilation. For more information, see [ReadyToRun images](../deploying/ready-to-run.md). Available since .NET Core 3.0 SDK.
64
+
65
+
To see warnings about missing dependencies that could cause runtime failures, use `PublishReadyToRunShowWarning=true`.
66
+
67
+
We recommend that you specify `PublishReadyToRun` in a publish profile rather than on the command line.
68
+
69
+
-`PublishSingleFile`
70
+
71
+
Packages the app into a platform-specific single-file executable. For more information about single-file publishing, see the [single-file bundler design document](https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md). Available since .NET Core 3.0 SDK.
72
+
73
+
We recommend that you specify this option in the project file rather than on the command line.
74
+
75
+
-`PublishTrimmed`
76
+
77
+
Trims unused libraries to reduce the deployment size of an app when publishing a self-contained executable. For more information, see [Trim self-contained deployments and executables](../deploying/trim-self-contained.md). Available since .NET Core 3.0 SDK as a preview feature.
78
+
79
+
We recommend that you specify this option in the project file rather than on the command line.
80
+
60
81
For more information, see the following resources:
@@ -139,28 +160,6 @@ For more information, see the following resources:
139
160
140
161
If you specify a relative path when publishing a solution, each project's output goes into a separate folder relative to the project file location. If you specify an absolute path when publishing a solution, all publish output for all projects goes into the specified folder.
141
162
142
-
-**`-p:PublishReadyToRun=true`**
143
-
144
-
Compiles application assemblies as ReadyToRun (R2R) format. R2R is a form of ahead-of-time (AOT) compilation. For more information, see [ReadyToRun images](../deploying/ready-to-run.md). Available since .NET Core 3.0 SDK.
145
-
146
-
To see warnings about missing dependencies that could cause runtime failures, use `-p:PublishReadyToRunShowWarnings=true`.
147
-
148
-
We recommend that you specify this option in a publish profile rather than on the command line. For more information, see [MSBuild](#msbuild).
149
-
150
-
-**`-p:PublishSingleFile=true`**
151
-
152
-
Packages the app into a platform-specific single-file executable. The executable is self-extracting and contains all dependencies (including native) that are required to run the app. When the app is first run, the application is extracted to a directory based on the app name and build identifier. Startup is faster when the application is run again. The application doesn't need to extract itself a second time unless a new version is used. Available since .NET Core 3.0 SDK.
153
-
154
-
For more information about single-file publishing, see the [single-file bundler design document](https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md).
155
-
156
-
We recommend that you specify this option in a publish profile rather than on the command line. For more information, see [MSBuild](#msbuild).
157
-
158
-
-**`-p:PublishTrimmed=true`**
159
-
160
-
Trims unused libraries to reduce the deployment size of an app when publishing a self-contained executable. For more information, see [Trim self-contained deployments and executables](../deploying/trim-self-contained.md). Available since .NET Core 3.0 SDK as a preview feature.
161
-
162
-
We recommend that you specify this option in a publish profile rather than on the command line. For more information, see [MSBuild](#msbuild).
163
-
164
163
-**`--self-contained [true|false]`**
165
164
166
165
Publishes the .NET runtime with your application so the runtime doesn't need to be installed on the target machine. Default is `true` if a runtime identifier is specified and the project is an executable project (not a library project). For more information, see [.NET application publishing](../deploying/index.md) and [Publish .NET apps with the .NET CLI](../deploying/deploy-with-cli.md).
0 commit comments