【发布时间】:2021-07-01 22:45:45
【问题描述】:
我正在尝试从我们的 Jenkins 构建服务器上的命令行执行 dotnet test,但它只是挂起:
Starting test execution, please wait...
在本地运行此命令时效果很好
如果我切换到使用dotnet xunit,它会失败并显示以下内容:
15:42:57 Locating binaries for framework netcoreapp2.1...
15:42:58 Running .NET Core 2.1 tests for framework netcoreapp2.1...
15:42:58 The specified framework version '2.1' could not be parsed
15:42:58 The specified framework 'Microsoft.NETCore.App', version '2.1' was not found.
15:42:58 - Check application dependencies and target a framework version installed at:
15:42:58 C:\Program Files\dotnet\
15:42:58 - Installing .NET Core prerequisites might help resolve this problem:
15:42:58 http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
15:42:58 - The .NET Core framework and SDK can be installed from:
15:42:58 https://aka.ms/dotnet-download
15:42:58 - The following versions are installed:
15:42:58 2.0.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58 2.0.9 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58 2.1.2 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58 2.1.3 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
15:42:58 2.1.4 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
根据错误消息,我们已经在服务器上安装了 dotnet core SDK,但我们似乎遗漏了一些东西。
我的测试项目如下:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.7.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="RichardSzalay.MockHttp" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>
</Project>
【问题讨论】:
-
"请注意,当您将 Version="2.1.1" 添加到您的项目时,您需要在部署服务器上安装 2.1.1 运行时才能使您的应用程序正常工作。" - github.com/aspnet/Home/issues/3250#issuecomment-403872208
标签: unit-testing jenkins .net-core xunit.net