找不到testhost.dll。请发布您的测试项目,然后重试 [英] Unable to find testhost.dll. Please publish your test project and retry

查看:207
本文介绍了找不到testhost.dll。请发布您的测试项目,然后重试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有单个XUnit测试方法的简单dotnet核心类库:

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

TestLib.csproj:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.SDK" Version="15.9.0" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.console" Version="2.4.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
    <PackageReference Include="xunit.runners" Version="2.0.0" />
  </ItemGroup>

</Project>

BasicTest.cs:
using Xunit;

namespace TestLib
{
    public class BasicTest
    {
        [Fact(DisplayName = "Basic unit test")]
        [Trait("Category", "unit")]
        public void TestStringHelper()
        {
            var sut = "sut";
            var verify = "sut";

            Assert.Equal(sut, verify);
        }
    }
}

如果我在CLI,然后输入 dotnet build 项目生成的内容。如果我键入 dotnet test 我会得到:

If I enter the project on the CLI and type dotnet build the project builds. If I type dotnet test I get this:

C:\git\Testing\TestLib> dotnet test
C:\git\Testing\TestLib\TestLib.csproj : warning NU1701: Package 'xunit.runner.visualstudio 2.4.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Build started, please wait...
C:\git\Testing\TestLib\TestLib.csproj : warning NU1701: Package 'xunit.runner.visualstudio 2.4.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Build completed.

Test run for C:\git\Testing\TestLib\bin\Debug\netstandard2.0\TestLib.dll(.NETStandard,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 16.0.0-preview-20181205-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
Unable to find C:\git\Testing\TestLib\bin\Debug\netstandard2.0\testhost.dll. Please publish your test project and retry.

Test Run Aborted.

我需要更改才能运行测试?

What do I need to change to get the test to run?

如果有帮助,VS Code也不会在其测试浏览器中显示测试。

If it helps, VS Code is not displaying the tests in its test explorer, either.

推荐答案

就我而言,问题是我瞄准了.NET Core 2.0并切换到.NET Core 2.1解决了该问题。但是我使用的是Microsoft.NET.Test.SDK v16.4.0,而不是15.9.0。

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.

这篇关于找不到testhost.dll。请发布您的测试项目,然后重试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆