我的 xUnit 测试在本地运行良好,但无法在 Azure DevOps 上运行。受测试的程序集是 .NET 5.0 程序集,测试程序集也是如此。
检查 VsTest 任务的日志文件,我看到以下内容
测试运行检测到针对不同框架和平台版本构建的 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 构建的。
Go to 有关管理这些设置的更多详细信息。
该链接并没有多大帮助(也许内容已更改)。我尝试在构建任务中使用命令行参数更改此设置: /Framework:net50 /Platform:x64 (AnyCPU 似乎不是有效的选项。)
...以及使用 .runsettings 文件(链接在我的构建任务中)
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<TargetPlatform>x64</TargetPlatform>
<TargetFrameworkVersion>net50</TargetFrameworkVersion>
</RunConfiguration>
</RunSettings>
...以及链接到管道的 BuildPlatform。
无论进行任何这些更改,日志文件中的错误(以及第一句中列出的当前设置)都保持不变。