Skip to main content

XUnit–.NET Standard

After creating a new project in Visual Studio to use for my unit tests, I added the following NuGet packages:

<PackageReference Include="xunit" Version="2.4.0" />
< PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />

However adding the second package resulted in the following warning message:

Package 'xunit.runner.visualstudio 2.4.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

So what did I do wrong? I wasn’t really thinking when creating my new project and my muscle memory made me click on a .NET Standard Class library. This is of course a great choice if you just want to build a library, but not a good fit for our unit tests where we should target a specific framework(.NET or .NET Core).

After changing the target framework to .NET Core the warning disappeared.

<PropertyGroup>
   < TargetFramework>netcoreapp3.0</TargetFramework>
< /PropertyGroup>

More info about this can be found here:

https://xunit.net/docs/why-no-netstandard