在 Azure Devops 编译的 aspnet core 3.0 测试项目上测试未 运行

Tests not run on aspnet core 3.0 test project compiled by Azure Devops

我有以下存储库 https://github.com/Mech0z/Foosball 在我有以下项目文件的地方,我希望管道中的测试步骤到 运行

https://github.com/Mech0z/Foosball/blob/master/Integrationstest/Integrationstest.csproj

它有以下包

<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />

而我的yaml文件是这样的

- task: VSTest@2
  inputs:
    projects: '**/*/Integrationstest.csproj'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

但是当它 运行s 我得到

Test run will use DLL(s) built for framework .NETFramework,Version=v4.0 and platform X86. Following DLL(s) do not match framework/platform settings. Integrationstest.dll is built for Framework .NETCoreApp,Version=v3.0 and Platform AnyCPU.

如何更改 yaml 文件中的 .NET 框架?

不使用 VSTest 任务,而是使用 DotNetCore 任务 运行 您的测试,例如

- task: DotNetCoreCLI@2
    inputs:
      command: "test"
      projects: "**/*/Integrationstest.csproj"
    displayName: Run the server-side tests

我在 Azure DevOps 中遇到了这个问题,我不得不将其添加到 Other Console Options

/Framework:.NETCoreApp,Version=v3.1

并指定编译测试的具体 .dll。在我的例子中是 UnitTests.dll,所以在 Test files 中我写道:

**\bin$(BuildConfiguration)\**\UnitTests.dll

它解决了这个问题。