无法找到 testhost.dll.请发布您的测试项目并重试 [英] Unable to find testhost.dll. Please publish your test project and retry

查看:71
本文介绍了无法找到 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:gitTestingTestLib> dotnet test
C:gitTestingTestLibTestLib.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:gitTestingTestLibTestLib.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:gitTestingTestLibinDebug
etstandard2.0TestLib.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:gitTestingTestLibinDebug
etstandard2.0	esthost.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天全站免登陆