Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I break the build with dotnet list --deprecated in a Azure Pipeline

I want to check my solution for the use of deprecated NuGet-Packages.

So I added

- task: dotNetCoreCLI@2
  name: checkDeprecatedNuGet
  inputs:
    command: 'custom'
    projects: '**/*.sln'
    custom: 'list'
    arguments: 'package --deprecated'

Now it lists the deprecated packages but the build is successfull.

Is there a possibility to break the build in this case?

like image 640
Martin Demberger Avatar asked Sep 14 '25 01:09

Martin Demberger


1 Answers

This is the solution I use now:

$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
  }
}
like image 54
Martin Demberger Avatar answered Sep 17 '25 18:09

Martin Demberger