Search code examples
nugetazure-pipelinesdotnetcorecli

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?


Solution

  • 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
      }
    }