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 marked IsTrimmable
- The SDK sets this to
copyused by default, but it is configurable via the property TrimMode
--action: the trimming granularity for assemblies not marked IsTrimmable
- The SDK sets this to
copy by default (so that assemblies which aren't marked IsTrimmable are kept).
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>).
@marek-safar @vitek-karas @samsp-msft @eerhardt
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 markedIsTrimmablecopyusedby default, but it is configurable via the propertyTrimMode--action: the trimming granularity for assemblies not markedIsTrimmablecopyby default (so that assemblies which aren't markedIsTrimmableare kept).We should expose a public MSBuild option that maps to the global
--action(maybeTrimmerDefaultAction), which allows developers to enable member-level trimming for the entire application by setting: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>).@marek-safar @vitek-karas @samsp-msft @eerhardt