Fix the trimming tests to link non-app assemblies correctly. (#40246)
authorEric Erhardt <eric.erhardt@microsoft.com>
Mon, 3 Aug 2020 20:08:04 +0000 (15:08 -0500)
committerGitHub <noreply@github.com>
Mon, 3 Aug 2020 20:08:04 +0000 (15:08 -0500)
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.

eng/testing/linker/SupportFiles/Directory.Build.targets

index 49422a3..a9dfda8 100644 (file)
   </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>