Skip to content

Commit 526c00c

Browse files
committed
[tests] Ignore trimmer warnings from NUnit.
NUnit is not trimmer-safe, and produces a lot of trimmer warnings. Ideally we'll fix NUnit or come up with an alternative (see #19911), but that's a significant amount of work. We also want to turn warnings into errors (to avoid adding more trimmer warnings by accident). So we disable trimmer warnings from NUnit. The method is somewhat complex, because there's no built-in way to ignore warnings for a given assembly, but both ILC and ILLink provides a way to collapse multiple warnings into a single warning (with a specific code) on a per assembly basis, and we can levarage this: * We enable all warnings for all assemblies (by setting `TrimmerSingleWarn=false`). * We enable the single-warning mode for NUnit only. * We ask the trimmer to not warn about the specific warning code given for the single-warning produced. The end result is that we won't get any trimmer warnings for NUnit. Ref: #19911
1 parent 0a00d75 commit 526c00c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/common/shared-dotnet.csproj

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@
6666
<DefineConstants>$(DefineConstants);NATIVEAOT</DefineConstants>
6767
</PropertyGroup>
6868

69+
<!-- Trimmer options -->
70+
<!-- We want to ignore any trimmer warnings from NUnit. We do this by:
71+
* Enable all warnings
72+
* Turn off all warnings (enabling single-warning mode) for NUnit
73+
* Ignore the warning produced when single-warning logic is triggered.
74+
-->
75+
<PropertyGroup>
76+
<!-- We want all the trimmer warnings -->
77+
<TrimmerSingleWarn Condition="'$(TrimmerSingleWarn)' == ''">true</TrimmerSingleWarn>
78+
<!-- IL2104: Assembly '...' produced trim warnings -->
79+
<NoWarn>$(NoWarn);IL2104</NoWarn>
80+
</PropertyGroup>
81+
<Target Name="IgnoreTrimmerWarningsInNUnit" BeforeTargets="PrepareForILLink">
82+
<ItemGroup>
83+
<ManagedAssemblyToLink Condition="'%(Filename)' == 'nunit.framework'">
84+
<TrimmerSingleWarn>true</TrimmerSingleWarn>
85+
</ManagedAssemblyToLink>
86+
<!-- The above ItemGroup doesn't work for NativeAOT, so pass the argument manually to ILC: https://github.com/dotnet/runtime/issues/94255 -->
87+
<IlcArg Include="--singlewarnassembly:nunit.framework" />
88+
</ItemGroup>
89+
</Target>
90+
6991
<ItemGroup>
7092
<PackageReference Include="NUnitLite" Version="3.12.0" Condition="'$(ExcludeNUnitLiteReference)' != 'true'" />
7193
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\external\Touch.Unit\Touch.Client\dotnet\$(_PlatformName)\Touch.Client-$(_PlatformName).dotnet.csproj" Condition="'$(ExcludeTouchUnitReference)' != 'true'" />

0 commit comments

Comments
 (0)