【发布时间】:2018-11-19 10:36:58
【问题描述】:
问题背景
我正在开发一个使用 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"
【问题讨论】:
标签: c# azure msbuild continuous-integration azure-devops