I have a simple dotnet core class library with a single XUnit test method:
TestLib.csproj:
Got this error, when trying to debug a unit test. Below are the steps I tried.
Yay!!! it worked :-) Never miss to try the last step ;-) Hope this helps someone like me.
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.
Had to add Microsoft.TestPlatform.TestHost
to get testhost.dll
.
I found that in this answer https://github.com/dotnet/sdk/issues/7171#issuecomment-261506546
If you are using xUnit, make sure your project type is not as netstanderd. As xUnit doesn't support netstanderd, change it to coreapp2.0 or others.
This happened to me after updating Microsoft.NET.Test.Sdk from v16.2.0 to v16.4.0 with <TargetFramework>netcoreapp2.0</TargetFramework>
. Updating to <TargetFramework>netcoreapp3.0</TargetFramework>
resolved the issue for me.
This could also be caused by inadvertently trying to run a non-test project, this usually happens when your test files filter is too wide.