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

Azure DevOps 2019中dotnet test的--filter等参数不识别问题咨询

问题根因
  • 当前使用CmdLine@2执行多行dotnet test命令时,包裹脚本的双引号+换行符被Azure DevOps 2019的代理错误解析,导致参数被拆分为多个独立命令,无法被dotnet CLI正常识别
  • 前置的Build任务arguments末尾存在多余的闭合双引号,会引发全局变量解析异常,间接影响后续任务的参数传递
  • 未使用Azure DevOps原生适配的DotNetCoreCLI@2test命令,自行拼接的命令行容易出现平台兼容问题
修复方案

方案1(推荐):替换为原生DotNetCoreCLI@2测试任务

直接使用官方封装的dotnet test任务,自动适配参数解析,无需处理换行转义问题,对应任务配置修改为:

- task: DotNetCoreCLI@2
  displayName: Coverage
  inputs:
    command: test
    projects: '**/*Test/*.csproj' # 也可替换为你的具体测试项目路径
    workingDirectory: $(System.DefaultWorkingDirectory)/wkf.WorkflowInvestorNotices
    arguments: >
      --filter FullyQualifiedName!=wkf.WorkflowInvestorNotices.Test.Service.FileImportTest.GivenCompareExcelFileWhenReadCellsThenReturnResults
      --no-restore
      --configuration $(BUILD_CONFIGURATION)
      /p:CollectCoverage=true

同时修正之前Build任务的语法错误,删除arguments末尾多余的双引号:

arguments: --no-restore --configuration $(BUILD_CONFIGURATION) --output $(Build.ArtifactStagingDirectory)/$(BUILD_CONFIGURATION)

方案2(保留CmdLine任务):修正脚本写法

如果需要保留CmdLine任务,修改script字段为多行字面量格式,去掉外层双引号:

- task: CmdLine@2
  displayName: Coverage
  inputs:
    script: |
      dotnet test --filter FullyQualifiedName!=wkf.WorkflowInvestorNotices.Test.Service.FileImportTest.GivenCompareExcelFileWhenReadCellsThenReturnResults \
      --no-restore \
      --configuration $(BUILD_CONFIGURATION) \
      /p:CollectCoverage=true
    workingDirectory: $(System.DefaultWorkingDirectory)/wkf.WorkflowInvestorNotices

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.09 21:39:03