Skip to content

Commit

Permalink
[tests] Ignore trimmer warnings from NUnit.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rolfbjarne committed Mar 22, 2024
1 parent 0a00d75 commit 526c00c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/common/shared-dotnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@
<DefineConstants>$(DefineConstants);NATIVEAOT</DefineConstants>
</PropertyGroup>

<!-- Trimmer options -->
<!-- We want to ignore any trimmer warnings from NUnit. We do this by:
* Enable all warnings
* Turn off all warnings (enabling single-warning mode) for NUnit
* Ignore the warning produced when single-warning logic is triggered.
-->
<PropertyGroup>
<!-- We want all the trimmer warnings -->
<TrimmerSingleWarn Condition="'$(TrimmerSingleWarn)' == ''">true</TrimmerSingleWarn>
<!-- IL2104: Assembly '...' produced trim warnings -->
<NoWarn>$(NoWarn);IL2104</NoWarn>
</PropertyGroup>
<Target Name="IgnoreTrimmerWarningsInNUnit" BeforeTargets="PrepareForILLink">
<ItemGroup>
<ManagedAssemblyToLink Condition="'%(Filename)' == 'nunit.framework'">
<TrimmerSingleWarn>true</TrimmerSingleWarn>
</ManagedAssemblyToLink>
<!-- The above ItemGroup doesn't work for NativeAOT, so pass the argument manually to ILC: https://github.com/dotnet/runtime/issues/94255 -->
<IlcArg Include="--singlewarnassembly:nunit.framework" />
</ItemGroup>
</Target>

<ItemGroup>
<PackageReference Include="NUnitLite" Version="3.12.0" Condition="'$(ExcludeNUnitLiteReference)' != 'true'" />
<ProjectReference Include="$(MSBuildThisFileDirectory)\..\..\external\Touch.Unit\Touch.Client\dotnet\$(_PlatformName)\Touch.Client-$(_PlatformName).dotnet.csproj" Condition="'$(ExcludeTouchUnitReference)' != 'true'" />
Expand Down

0 comments on commit 526c00c

Please sign in to comment.