Azure-DevOps 显示构建警告

ful*_*ckz 5 c# msbuild continuous-integration azure azure-devops

问题背景

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

# $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'
}
Run Code Online (Sandbox Code Playgroud)

问题

目前,$LASTEXITCODE可以是0 (no errors)1 (error)。如果退出代码为 0,一切正常,Azure 会显示绿色的通过徽章;如果是 1 Azure 将显示红色错误徽章。但是,当构建中出现警告时,它们会显示在日志中,并且 Azure 会显示绿色徽章。

目标

我的目标是让 Azure 在出现警告时显示黄色/橙色警告徽章。这可能吗?如何实现?非常感谢您的宝贵时间!

尝试的解决方案

在 C# 项目属性中,Warning level将其设置为4; 所以我尝试对 power shell 脚本进行修改,但是没有成功。

& $buildTools $solution 4> 'warning.txt'
Run Code Online (Sandbox Code Playgroud)

更新解决方案

感谢DJ的回答!最终的构建线如下所示:

# $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"
Run Code Online (Sandbox Code Playgroud)

D.J*_*.J. 3

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

  • 我找到了解决办法!如果我只用“”包裹“/fl /flp”部分,它就会按预期工作。再次感谢您! (2认同)