Unable to find testhost.dll. Please publish your test project and retry
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.