问题描述
我有 xUnit 测试,它们在本地运行良好,但无法在 Azure DevOps 上运行。被测程序集和测试程序集一样是 .NET 5.0 程序集。
测试运行检测到为不同框架和平台版本构建的 DLL。以下 DLL 与当前设置不匹配,即 .NETFramework、Version=v5.0 框架和 X86 平台。
UnitTests.dll 是为 Framework .NETCoreApp,Version=v5.0 和 Platform Anycpu 构建的。
Microsoft.TestPlatform.CommunicationUtilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform Anycpu 构建的。
Microsoft.TestPlatform.CoreUtilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform Anycpu 构建的。
Microsoft.TestPlatform.CrossplatEngine.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform Anycpu 构建的。
Microsoft.TestPlatform.PlatformAbstractions.dll 是为 Framework .NETCoreApp,Version=v2.1 和 Platform Anycpu 构建的。
Microsoft.TestPlatform.Utilities.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform Anycpu 构建的。
Microsoft.VisualStudio.TestPlatform.Common.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform Anycpu 构建的。
Microsoft.VisualStudio.TestPlatform.ObjectModel.dll 是为 Framework .NETStandard、Version=v2.0 和 Platform Anycpu 构建的。
testhost.dll 是为 Framework .NETCoreApp,Version=v2.1 和 Platform Anycpu 构建的。
xunit.runner.visualstudio.dotnetcore.testadapter.dll 是为 Framework .NETCoreApp,Version=v2.1 和 Platform Anycpu 构建的。
有关管理这些设置的更多详细信息,请转到 http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409。
该链接并没有太大帮助(可能内容已更改)。我尝试在构建任务中使用命令行参数更改此设置:/Framework:net50 /Platform:x64(Anycpu 似乎不是有效选项。)
... 以及使用 .runsettings 文件(在我的构建任务中链接)
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<runconfiguration>
<TargetPlatform>x64</TargetPlatform>
<TargetFrameworkVersion>net50</TargetFrameworkVersion>
</runconfiguration>
</RunSettings>
无论这些更改如何,日志文件中的错误(以及第一句中列出的当前设置)保持不变。
解决方法
xUnit 测试在本地运行,但不在 Azure DevOps 上运行
根据错误信息:
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU
您的测试项目似乎使用的是旧版 SDK。
为了解决这个问题,请尝试使用dot net test代替VS test task来测试dll文件:
- task: DotNetCoreCLI@2
displayName: Test
inputs:
command: test
projects: '**/*[Tt]ests/*.csproj'
arguments: '--configuration $(BuildConfiguration)'
enabled: false