How to unit test multi-targeting projects that go back to .NET 2.0

69 Views Asked by At

I often create tiny compatibility libraries that are multi-targeting projects that support everything from .NET 8.0 back to .NET 2.0. I am totally happy with how that is supported by Visual Studio, msbuild and the SDK-style projects, e.g.:

<TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;netcoreapp3.0;netcoreapp2.2;netcoreapp2.1;netcoreapp2.0;netcoreapp1.1;netcoreapp1.0;netstandard2.1;netstandard2.0;netstandard1.6;netstandard1.5;netstandard1.4;netstandard1.3;netstandard1.2;netstandard1.1;netstandard1.0;net481;net48;net472;net471;net47;net462;net461;net46;net452;net451;net45;net403;net40;net35;net30;net20</TargetFrameworks>

but I get stuck with the testing. If I try to do a similar thing with the test project, e.g. <TargetFrameworks>net8.0;net7.0;net6.0;net5.0;netcoreapp3.1;netcoreapp3.0;netcoreapp2.2;netcoreapp2.1;netcoreapp2.0;netcoreapp1.1;netcoreapp1.0;net481;net48;net472;net471;net47;net462;net461;net46;net452;net451;net45;net403;net40;net35;net30;net20</TargetFrameworks> (yes I know about removing the .NET Standards which need a runtime) it fails because only frameworks back to .NET 4.5 are supported *).

How do I test all unit tests of all frameworks? I do not care about what framework to use, whether this is MSTest, NUnit, xUnit or something else and I do not mind some if-then-else in the project definition (e.g. if .NET < 4.5 use MSTest1 otherwise MSTest2) but I like to avoid dozens of projects targeting a single framework and the test runner must be reliable, playing always all tests in all given frameworks.

*) But also make troubles, I often also experience that not all tests of all frameworks are executed, some just are ignored and not always the same.

0

There are 0 best solutions below