Installing Microsoft.NET.Test.Sdk
package from nuget package manager solved my issue.
In my case, the problem was that I was targeting .NET Core 2.0 and switching to .NET Core 2.1 solved the problem. However I was using Microsoft.NET.Test.SDK v16.4.0 instead of 15.9.0.
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.
In my case the problem was that I have an extension project for xunit. There is also a test project to test the extensions. When I ran dotnet test
on my solution, my extension project was also picked up as a unit test project (it took me some time to realize this). The reason for this is that it references some xunit packages. One of these xunit packages automatically sets the <IsTestProject>true</IsTestProject>
property in you csprj file. This is actually a good thing since 99.99% of the projects that reference xunit are actually unit tests. I could finally solve this by explicitly setting
<PropertyGroup>
...
<IsTestProject>false</IsTestProject>
...
</PropertyGroup>
Manually in my csproj file. Then the problem went away.
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 https://stackoverflow.com/a/63786758/3248302
I've encountered this a couple of times and I always forget what's up. Most recently I had:
Packages for my test project:
I was seeing:
Unable to find C:\PATH\bin\Debug\netstandard2.0\testhost.dll. Please publish your test project and retry.
And all that I needed to do was add to my test project the missing nuget package: "Microsoft.NET.Test.SDK"
Everything was back to normal at this point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With