【问题标题】:How can I break the build with dotnet list --deprecated in a Azure Pipeline如何在 Azure 管道中使用 dotnet list --deprecated 中断构建
【发布时间】:2023-03-26 20:50:01
【问题描述】:
我想检查我的解决方案是否使用了已弃用的 NuGet 包。
所以我加了
- task: dotNetCoreCLI@2
name: checkDeprecatedNuGet
inputs:
command: 'custom'
projects: '**/*.sln'
custom: 'list'
arguments: 'package --deprecated'
现在它列出了已弃用的包,但构建成功。
在这种情况下是否有可能破坏构建?
【问题讨论】:
标签:
nuget
azure-pipelines
dotnetcorecli
【解决方案1】:
这是我现在使用的解决方案:
$projectDirectory = "$(Agent.BuildDirectory)/s/$(RepoName)"
$solutions = Get-ChildItem -Path $projectDirectory/** -Name -Include *.sln
foreach ($solution in $solutions)
{
$output = dotnet list $projectDirectory/$solution package --deprecated
$errors = $output | Select-String '>'
if ($errors.Count -gt 0)
{
foreach ($err in $errors)
{
Write-Host "##vso[task.logissue type=error]Reference to deprecated NuGet-package $err"
}
exit 1
}
else
{
Write-Host "No deprecated NuGet-package"
exit 0
}
}
【解决方案2】:
如果您的意思是在存在已弃用的软件包时中断构建,我认为您无法在 dotNetCoreCLI 任务中实现它。此任务运行成功后,将视为“通过”。
您可以尝试使用 powershell 任务运行 dotNetCore 命令,如果有已弃用的包,则编写错误以使构建失败:
# Writes an error to build summary and to log in red text
Write-Host "##vso[task.LogIssue type=error;]This is the error"
如果您希望此错误导致构建失败,请添加以下行:
exit 1