You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure Pipeline混合.NET48与.NETCoreApp3.1测试无法运行的解决方案

Azure Pipeline VSTest任务运行.NET Framework 4.8单元测试失败的解决方案

原Pipeline配置

- task: VisualStudioTestPlatformInstaller@1
  inputs:
    packageFeedSelector: 'nugetOrg'
    versionSelector: 'specificVersion'
    testPlatformVersion: '17.6.3'

- task: VSTest@2
  displayName: 'Run Unit Tests'
  inputs:
    testAssemblyVer2: |
      **\*FunctionalTests.dll
      **\*UnitTests.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    vsTestVersion: 'toolsInstaller'
    codeCoverageEnabled: true
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    diagnosticsEnabled: true

问题场景

项目包含两类单元测试:

  • 仅以.NET Framework 4.8为目标框架的测试
  • 同时以.NET Framework 4.8和.NET Core 3.1为目标框架的测试

近期发现仅.NET Framework 4.8的测试无法运行,尝试通过设置otherConsoleOptions: '/Framework:net48'指定目标框架,但未解决问题。

解决步骤

经过调试,通过以下三步解决问题:

  1. 在VSTest@2任务中添加配置项:pathtoCustomTestAdapters: '$(Build.SourcesDirectory)\\TestTools'
  2. 在项目根目录创建TestTools文件夹(也可直接引用单元测试项目的bin目录)
  3. 将MS Test NuGet包中的以下DLL放入TestTools文件夹:
    • Microsoft.TestPlatform.AdapterUtilities.dll
    • Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll
    • Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll
    • Microsoft.VisualStudio.TestPlatform.TestFramework.dll
    • Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll

内容的提问来源于stack exchange,提问作者ree6

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 02:55:06