-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
In .NET 6, we are introducing [assembly: AssemblyMetadata("IsTrimmable", "True")]
as a way to opt a library into trimming. MSBuild metadata can also be used to override this per-assembly.
With this change, the linker has two global knobs to control trimming:
--trim-mode
: the trimming granularity for assemblies markedIsTrimmable
- The SDK sets this to
copyused
by default, but it is configurable via the propertyTrimMode
- The SDK sets this to
--action
: the trimming granularity for assemblies not markedIsTrimmable
- The SDK sets this to
copy
by default (so that assemblies which aren't markedIsTrimmable
are kept).
- The SDK sets this to
We should expose a public MSBuild option that maps to the global --action
(maybe TrimmerDefaultAction
), which allows developers to enable member-level trimming for the entire application by setting:
<TrimMode>link</TrimMode>
<TrimmerDefaultAction>link</TrimmerDefaultAction>
When we discussed full-app trimming earlier, we were hesitant to make it too easy (see the notes under TrimAllAssemblies
).
On the other hand, the option is already there (introduced in #16094), so the real question is just whether it should be exposed to the user (and if so, what the name should be). Note that xamarin-android already has some user-facing knobs to do exactly this (<AndroidLinkMode>Full</AndroidLinkMode>
).