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

前端 未结 19 1066
星月不相逢
星月不相逢 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 11:58

    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.

    0 讨论(0)
  • 2021-02-01 11:58

    Fixed it by installing xunit.runner.visualstudio.

    0 讨论(0)
  • 2021-02-01 11:58

    This error can occur if you upgrade xunit.runner.visualstudio to a version greater than 2.4.1. Versions up to and including 2.4.1 include a reference to Microsoft.NET.Test.Sdk but later ones don't, so you need to include the reference in your own project.

    Interestingly, I found that NCrunch still ran my tests without the additional reference, even though I couldn't run them via the CLI.

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

    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.

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

    same issue i faced for Nunit (.net core 3.1) project . I was using Microsoft.NET.Test.SDK v16.6.1, I downgraded the version to 15.9.0. And it start working

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

    In my case, it was necessary to include a reference to MsTest.TestAdapter module using nuget.

    A fresh project with MSTest.TestFramework and Microsoft.Net.Test.Sdk was not enough to run a single unit test.

    Noticing in my case I was using a test project targeting .NET framework 4.8 and not .NET core. Although, I strongly believe this fix might apply to that platform as well

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