Skip to content

Commit

Permalink
Add trimming breaking change (#30408)
Browse files Browse the repository at this point in the history
  • Loading branch information
gewarren authored Aug 2, 2022
1 parent 850f087 commit 60a5814
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/core/compatibility/7.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ If you're migrating an app to .NET 7, the breaking changes listed here might aff

| Title | Binary compatible | Source compatible | Introduced |
| - | :-: | :-: | - |
| [All assemblies trimmed by default](deployment/7.0/trim-all-assemblies.md) | ✔️ || Preview 7 |
| [Multi-level lookup is disabled](deployment/7.0/multilevel-lookup.md) || ✔️ | Preview 4 |
| [x86 host path on 64-bit Windows](deployment/7.0/x86-host-path.md) | ✔️ | ✔️ | Preview 6 |

Expand Down
54 changes: 54 additions & 0 deletions docs/core/compatibility/deployment/7.0/trim-all-assemblies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "Breaking change: All assemblies trimmed by default"
description: Learn about the .NET 7 breaking change in deployment where all assemblies in a console app are trimmed by default.
ms.date: 07/28/2022
---
# All assemblies trimmed by default

Trimming now trims all assemblies in console apps, by default. This change only affects apps that are published with `PublishTrimmed=true`, and it only breaks apps that had existing trim warnings. It also only affects plain .NET apps that don't use the Windows Desktop, Android, iOS, WASM, or ASP.NET SDK.

## Previous behavior

Previously, only assemblies that were opted-in with `<IsTrimmable>true</IsTrimmable>` in the library project file were trimmed.

## New behavior

Starting in .NET 7, trimming trims all the assemblies in the app by default. Apps that may have previously worked with `PublishTrimmed` may not work in .NET 7. However, only apps with trim warnings will be affected. If your app has no trim warnings, the change in behavior should not cause any adverse affects, and will likely decrease the app size.

If your app did have trim warnings, you may see changes in behavior or exceptions. For example, an app that uses `Newtonsoft.Json` or `System.Text.Json` without source generation to serialize and deserialize a type in the user project may have functioned before the change, because types in the user project were fully preserved. However, one or more trim warnings (warning codes `ILxxxx`) would have been present. Now, types in the user project are trimmed, and serialization may fail or produce unexpected results.

## Version introduced

.NET 7 Preview 7

## Type of breaking change

This change can affect [source compatibility](../../categories.md#source-compatibility).

## Reason for change

This change helps to decrease app size without users having to explicitly opt in and aligns with user expectations that the entire app is trimmed unless noted otherwise.

## Recommended action

The best resolution is to resolve all the trim warnings in your application. For information about resolving the warnings in your own libraries, see [Introduction to trim warnings](../../../deploying/trimming/fixing-warnings.md). For other libraries, contact the author to request that they resolve the warnings, or choose a different library that already supports trimming. For example, you can switch to <xref:System.Text.Json?displayProperty=fullName> with [source generation](../../../../standard/serialization/system-text-json-source-generation.md), which supports trimming, instead of `Newtonsoft.Json`.

To revert to the previous behavior, set the `TrimMode` property to `partial`, which is the pre-.NET 7 behavior.

```xml
<TrimMode>partial</TrimMode>
```

The default .NET 7+ value is `full`:

```xml
<TrimMode>full</TrimMode>
```

## Affected APIs

None.

## See also

- [Trimming options](../../../deploying/trimming/trimming-options.md)
4 changes: 4 additions & 0 deletions docs/core/compatibility/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ items:
href: cryptography/7.0/x500-distinguished-names.md
- name: Deployment
items:
- name: All assemblies trimmed by default
href: deployment/7.0/trim-all-assemblies.md
- name: Multi-level lookup is disabled
href: deployment/7.0/multilevel-lookup.md
- name: x86 host path on 64-bit Windows
Expand Down Expand Up @@ -933,6 +935,8 @@ items:
items:
- name: .NET 7
items:
- name: All assemblies trimmed by default
href: deployment/7.0/trim-all-assemblies.md
- name: Multi-level lookup is disabled
href: deployment/7.0/multilevel-lookup.md
- name: x86 host path on 64-bit Windows
Expand Down

0 comments on commit 60a5814

Please sign in to comment.