【问题标题】:Azure-DevOps display build warningAzure-DevOps 显示生成警告
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 谢谢你给了我希望!我已将构建行更改为& $buildTools $solution /t:Clean,Build /p:Configuration=Release,Platform=x86 /fl1 /flp1:warningsonly;logfile=$warningsFile,其中$warningsFile 是同一目录中文件的路径。然而,这一行会引发以下错误:The term 'logfile=$warningsFile' is not recognized as the name of a cmdlet, function, script file... 接下来你会推荐我尝试什么?
    • 用 " 包装你的参数列表
    • 当我用" 包装参数时它根本不起作用,即使我删除了/fl /flp 部分,它也会因为" 而引发错误。
    • 我找到了解决办法!如果我只用" 包装/fl /flp 部分,它会按预期工作。再次感谢您!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多