Unable to find testhost.dll. Please publish your test project and retry

前端 未结 19 1067
星月不相逢
星月不相逢 2021-02-01 11:40

I have a simple dotnet core class library with a single XUnit test method:

TestLib.csproj:


  
            


        
相关标签:
19条回答
  • 2021-02-01 12:03

    If you are targeting netstandard2.0 this will not work. If are using .NET Core. make sure the .csproj contains the following lines:

    <TargetFramework>netcoreapp3.0</TargetFramework>

    and also contains the package Microsoft.NET.Test.Sdk

    0 讨论(0)
  • 2021-02-01 12:06

    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 stackoverflow.com/a/63786758/3248302

    0 讨论(0)
  • 2021-02-01 12:07

    I was building a netcoreapp2.2 test project and then trying to run dotnet vstest from the bin folder. I noticed that the Microsoft Test DLLs from:

    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.0.1" />
    

    were not being output to my bin folder. Instead of just building, I ran a publish instead which did include the necessary DLLs in the output folder and I was then able to run dotnet vstest from there.

    0 讨论(0)
  • 2021-02-01 12:08

    If you are running a project by cloning than Solution is to install the Microsoft.NET.Test.Sdk. How to : Tools>Nuget Package Manager>Manage Nuget Packages For Solution...>Search for Microsoft.NET.Test.Sdk and install for your test project.

    0 讨论(0)
  • 2021-02-01 12:12

    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.

    0 讨论(0)
  • 2021-02-01 12:13

    Installing Microsoft.NET.Test.Sdk package from nuget package manager solved my issue.

    0 讨论(0)
提交回复
热议问题