Description
Is your feature request related to a problem? Please describe.
With the rise of source generators, and syntactic sugar like record
, a lot of code is being generated that may not be required by an app. This code may end up being in the main assembly, and this assembly is not currently eligible for trimming, as its mode passed to the ILLinker is set to copy
, therefore disabling general trimming, but also more importantly feature substitutions.
There's one workaround that can be applied to change the "root assembly" trimming mode (based on this piece of code):
<Target Name="_AdjustILLinkParameters" AfterTargets="PrepareForILLink">
<ItemGroup>
<TrimmerRootAssembly Update="@(TrimmerRootAssembly)" RootMode="library" />
</ItemGroup>
</Target>
Yet an official solution would be more appropriate.
Describe the solution you'd like
In a similar way <TrimMode>copyused</TrimMode>
can be used, something like <TrimRootAssemblyMode>library</TrimRootAssemblyMode>
, following the modes provided by ILLink: default
, all
, visible
, entrypoint
and library
.
Additional context
Note that this feature is particularly important in the case of iOS, Android, Catalyst and macOS.
While moving the code to a separate assembly could remove this "root assembly" issue, Visual Studio does not does not support partial build of multi-targeted assemblies. This causes dependent projects (while the main assembly only builds one target framework) to build the full set of target frameworks, a very expensive operation slowing down the dev inner loop.