Azure-DevOps显示生成警告

时间:2018-11-19 10:36:59

标签: c# azure msbuild continuous-integration azure-devops

问题背景

我正在研究一个使用Azure DevOps for CI的C#项目。当项目推送到Azure时,我有一个正在运行的Power Shell文件。构建文件的相关部分是:

# $buildTools is the path to MSBuild.exe
# $solution is the path to the project's .sln file
& $buildTools $solution /t:Clean,Build /p:Configuration=Release,Platform=x86
if ($LASTEXITCODE -eq 0) {
  Write-Host 'Build completed successfully!'
} else {
  Write-Host '##vso[task.logissue type=error;]There were errors during the build of the application'
}

问题

当前,$LASTEXITCODE可以是0 (no errors)1 (error)。如果退出代码为0,则一切正常,Azure会显示绿色的通过标志;如果为1,Azure将显示红色的错误标志。但是,当生成警告时,警告会显示在日志中,而Azure将显示绿色标志。

目标

我的目标是在有警告时使Azure显示黄色/橙色警告标志。这有可能吗?非常感谢您的宝贵时间!

尝试的解决方法

在C#项目属性中,Warning level设置为4;所以我尝试对Power Shell脚本进行此修改,但是,修改没有奏效。

& $buildTools $solution 4> 'warning.txt'

使用解决方案更新

感谢D.J.'s answer!最终的构建行如下所示:

# $warningsFile is a path to a file that will contain all the warnings
& $buildTools $solution /t:Clean,Build /p:Configuration=Release,Platform=x86 /fl1 "/flp1:$warningsFile;warningsonly"

1 个答案:

答案 0 :(得分:2)

您可以使用此-> https://docs.microsoft.com/en-us/visualstudio/msbuild/obtaining-build-logs-with-msbuild?view=vs-2017#save-the-log-output-to-multiple-files并将所有警告写入日志文件,然后检查日志文件是否包含任何内容,然后使用theese命令(https://github.com/Microsoft/azure-pipelines-tasks/blob/master/docs/authoring/commands.md)将警告写入输出中