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

如何在Azure DevOps中通过DotNetCoreCLI@2实现将警告视为错误

如何在Azure DevOps的DotNetCoreCLI@2任务中启用“将警告视为错误”功能

此前有文章介绍过VSBuild@1任务中启用“将警告视为错误”的配置方法,现在需要在以下DotNetCoreCLI@2发布任务中实现同样功能:

- task: DotNetCoreCLI@2
  displayName: dotnet publish
  inputs:
    command: publish
    arguments: '--property:PublishDir=$(Build.BinariesDirectory) --self-contained true'
    configuration: $(BuildConfiguration)
    projects: $(Solution)
    modifyOutputPath: true
    publishWebProjects: true
    zipAfterPublish: false

只需在arguments参数里添加--property:TreatWarningsAsErrors=true属性,就能让dotnet publish过程将所有警告视为错误,触发构建失败。修改后的任务配置如下:

- task: DotNetCoreCLI@2
  displayName: dotnet publish
  inputs:
    command: publish
    arguments: '--property:PublishDir=$(Build.BinariesDirectory) --self-contained true --property:TreatWarningsAsErrors=true'
    configuration: $(BuildConfiguration)
    projects: $(Solution)
    modifyOutputPath: true
    publishWebProjects: true
    zipAfterPublish: false

也可以简化参数写法,把多个--property合并成一个:

arguments: '--property:PublishDir=$(Build.BinariesDirectory);TreatWarningsAsErrors=true --self-contained true'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 19:52:41