Fractal
Fractal

Reputation: 1897

Unable to find testhost.dll. Please publish your test project and retry. (.Net Core 2.1)

I have a C# (selenium + NUnit + Specflow) .Net Core 2.1 project (vs 2017).

My project references the Microsoft.TestPlatform.TestHost nuget which contains the testhost.dll. The tests run on my computer but when I try to run them in Azure DevOps they fail with the error, "Unable to find testhost.dll".

This makes sense because when I build the project on my computer, testhost.dll is not added to the bin directory although the project references the Microsoft.TestPlatform.TestHost nuget which contains the testhost.dll.

Question: Why does the testhost.dll not get added to the bin directory on build?

Note: I have looked at other posts about this error message and most of the time their problem is that they are not referencing the assembly. However, I am referencing the nuget.

  1. Project does reference testhost.dll

enter image description here

  1. Microsoft.TestPlatform.TestHost is in the *.csproj file

enter image description here

  1. when run on command line on my computer it runs fine (testhost.dll is not needed when run on my machine because VS is installed)

enter image description here

  1. When run in Azure Pipeline, it fails stating testhost.dll could not be found (which makes sense since it never gets copied to the bin directory. Not sure why it doesn't get added to the bin though) enter image description here

Upvotes: 3

Views: 2426

Answers (2)

Daniel Fisher  lennybacon
Daniel Fisher lennybacon

Reputation: 4174

Just run the Publish task (dotnet or msbuild) prior to the test execution and use the test libraries from your publish location.

Upvotes: 0

Fractal
Fractal

Reputation: 1897

This is more than likely the issue. I copied the files to the artifact instead of publishing. I'll test and see if this works. Will update this post after I try this out. [Update: Yes, the issue was that I needed to publish in order for the needed *.dlls to get placed into the bin directory]

Answer in the image came from the following github page.

enter image description here


These are the Instructions I was following. They were actually really good. I used it to get comfortable running a test project in azure before integrating it into a software pipeline. You'll see minute 11:33 shows that the tests need to have a 'Publish' step in the job. How to Run .NET Core Selenium Tests in Azure DevOps

Upvotes: 1

Related Questions