I was hoping this problem would resolve itself, but it hasn’t so I am writing about it to document it to refer to in the future. I ran into this problem twice now and it annoys me because it shows how underbaked dot net core still is.
Assuming you have already done the following things:
- You created a new class library for .net core
- Via NuGet you have added the following things:
- Created a basic test of any kind
When you go to run your test, it just won’t run. Instead you get an error like this one:
[9/1/2019 20:36:11 Error] Unable to find C:\MyProject.Tests\bin\Debug\netcoreapp2.1\testhost.dll. Please publish your test project and retry.
All credit goes to GitHub user Baxtex who provided a very simple solution that fixes everything: https://github.com/Microsoft/vstest/issues/1870#issuecomment-452252057
For the sake of preservation of the answer, I am copying it here, but the citation is above:
Solution is to install the Microsoft.NET.Test.Sdk:
Tools>Nuget Package Manager>Manage Nuget Packages For Solution…>Search for Microsoft.NET.Test.Sdk and install for your test project.
In my opinion I shouldn’t have to install a Microsoft library to use my NUnit library. I could blame NUnit for not making this a necessary dependency, but at the same time you would think that instead of getting that useless error above it would say “Install the Microsoft.NET.Test.Sdk from NuGet to continue.”
I’m still not fond of dot net core and things like this are why.