I have a simple dotnet core class library with a single XUnit test method:
TestLib.csproj:
If you are targeting netstandard2.0 this will not work. If are using .NET Core. make sure the .csproj contains the following lines:
<TargetFramework>netcoreapp3.0</TargetFramework>
and also contains the package Microsoft.NET.Test.Sdk
I found a very interesting compatibility issue with a version. I did upgrade just as a normal practice, my code, and I switched to xUnit.runner.visualstudio 2.4.2. It stopped working for .Net Core 3.1. I had to downgrade to 2.4.1 and it started working again.
Additional information after one of my comments.
The package xunit.runner.visualstudio versions <= 2.4.1 includes a reference to Microsoft.NET.Test.Sdk. Later versions don't, so you need to add the reference to your project.
See stackoverflow.com/a/63786758/3248302
I was building a netcoreapp2.2 test project and then trying to run dotnet vstest
from the bin folder. I noticed that the Microsoft Test DLLs from:
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
were not being output to my bin folder. Instead of just building, I ran a publish instead which did include the necessary DLLs in the output folder and I was then able to run dotnet vstest
from there.
If you are running a project by cloning than Solution is to install the Microsoft.NET.Test.Sdk. How to : Tools>Nuget Package Manager>Manage Nuget Packages For Solution...>Search for Microsoft.NET.Test.Sdk and install for your test project.
I had created a class library and tried to use the XUnit NuGet package in it.
What I should have done was created an XUnit project using this command: dotnet new xunit -n TestProject
I found this helpful page.
Installing Microsoft.NET.Test.Sdk
package from nuget package manager solved my issue.