MSTest v2: Testing against multiple frameworks

This post is part of the serie 'MSTest v2'. Be sure to check out the rest of the blog posts of the serie!

When you create a .NET library, you can target multiple frameworks: .NET Framework, .NET Core, Universal Windows Platform, etc., and their different versions. You can now write code that targets .NET Standard to target a maximum of platform at once. However, you should test your code runs well on all these platforms. For example, if you create a .NET Standard 2.0 library, you may want to test it on .NET Core 2.0 and .NET Framework 4.6.1. You'll find the compatibility table of .NET Standard in the documentation

Using the new csproj, you can set multiple target frameworks. The test runner will use all of them.

  1. Open the csproj of the test project.
  2. Replace TargetFramework by TargetFrameworks (plural) and set the desired frameworks separated by a semicolon. The list of frameworks is available in the documentation.




  1. Run the tests using the command line:
dotnet test

The unit tests are run three times, once per platform. This way you are sure your code will behave the same way on all platforms.

Note: The test explorer of Visual Studio doesn't support multiple frameworks. It will only display and execute the test of one platform.