The PrepareForILLink target will pass any ManagedAssemblyToLink that isn't marked as IsTrimmable=true to a TrimmerRootAssembly. This will cause the assembly to be passed to the linker with `-a`, which means the asesmbly won't be fully trimmed. So any assembly outside of the runtimepack will be passed with -a (for example Microsoft.Extensions.*).
Fix this by moving to BeforeTargets=PrepareForILLink and marking the single application assembly as a root.
</Target>
<Target Name="EnsureAllAssembliesAreLinked"
- AfterTargets="PrepareForILLink">
+ BeforeTargets="PrepareForILLink">
<ItemGroup>
<ManagedAssemblyToLink>
<TrimMode>link</TrimMode>
</ManagedAssemblyToLink>
+
+ <!-- Pass the app assembly as a root -->
+ <TrimmerRootAssembly Include="@(IntermediateAssembly)" />
</ItemGroup>
</Target>