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

前端 未结 19 1068
星月不相逢
星月不相逢 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:13

    Got this error, when trying to debug a unit test. Below are the steps I tried.

    • Step 1: Installed Microsof.TestPlatform.TestHost and tried to run the test but no luck.
    • Step 2: Changed Target framework from .NET Core 2.0 to 2.1 and tried to run the test but no luck.
    • Step 3: Closed and opened VS2017 and tried to run.

    Yay!!! it worked :-) Never miss to try the last step ;-) Hope this helps someone like me.

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

    I've encountered this a couple of times and I always forget what's up. Most recently I had:

    • Class Library -> Targeting .NET Core 3.0
    • Test Project -> Targeting .NET Core 3.1

    Packages for my test project:

    • Moq -> 4.14.1
    • xUnit -> 2.4.1
    • xUnit.Runner.VisualStudio -> 2.4.2

    I was seeing:

    Unable to find C:\PATH\bin\Debug\netstandard2.0\testhost.dll. Please publish your test project and retry.

    And all that I needed to do was add to my test project the missing nuget package: "Microsoft.NET.Test.SDK"

    Everything was back to normal at this point.

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

    Had to add Microsoft.TestPlatform.TestHost to get testhost.dll. I found that in this answer https://github.com/dotnet/sdk/issues/7171#issuecomment-261506546

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

    If you are using xUnit, make sure your project type is not as netstanderd. As xUnit doesn't support netstanderd, change it to coreapp2.0 or others.

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

    This happened to me after updating Microsoft.NET.Test.Sdk from v16.2.0 to v16.4.0 with <TargetFramework>netcoreapp2.0</TargetFramework>. Updating to <TargetFramework>netcoreapp3.0</TargetFramework> resolved the issue for me.

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

    This could also be caused by inadvertently trying to run a non-test project, this usually happens when your test files filter is too wide.

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