如何在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
相关产品推荐
相关产品推荐

