/azure-devops-dotnet-warnings

Show build issues (warnings / errors) in azure devops for .NET Core projects.

azure-devops-dotnet-warnings

Show build issues (warnings / errors) in Azure Devops for .NET Core projects. Solution for the issue mentioned here: microsoft/azure-pipelines-tasks#7749

The problem

When building .NET core projects in the Azure Devops pipeline with the dotnetcli, the build warnings are not shown in the Build Log / Build Summary views.

The solution

With azure-pipelines.yml

Write the dotnet build output to a log file and convert all the issues to a VSO issue. This is done in the azure-pipelines.yml in this repo. You are free to copy this to your own repo!

With classic build pipelines

  1. Add the .NET Core restore task to your build pipeline

  2. Add the .NET Core build task to your bulid pipeline and update the arguments to:
    --configuration $(BuildConfiguration) --no-incremental /flp:v=q /flp:logfile=MyLog.log image

  3. Add the Powershell task to your build after the .NET Core - build task. Set the Type to Inline. Copy paste this script to the Script field:

    $output = Get-Content -Path "$(System.DefaultWorkingDirectory)/MyLog.log";
    $warnings = $output | Select-String -Pattern ".*:\s";
    $hasErrors = $false;
    [regex]$issueTypeRegex = "(warning|error)";
    [regex]$issueLocationRegex = "(\d+,\d+)";
    [regex]$sourcePathRegex = "^[^/(]*";
    [regex]$issueCodeRegex = "(?<=(warning|error) )[A-Za-z0-9]+";
    [regex]$messageRegex = "(?<=((warning|error) [A-Za-z0-9]+: )).*";
    $warnings | Foreach-Object { 
      $issueLocationMatch = $issueLocationRegex.Matches($_)[0];
      if ($issueLocationMatch) { $issueLocation = $issueLocationMatch.value.split(","); }
      else { $issueLocation = "unknown"; }
      
      $issueLocation = $issueLocationMatch.value.split(",");
      $issueType = $issueTypeRegex.Matches($_)[0];
      $sourcepath = $sourcePathRegex.Matches($_)[0];
      $linenumber = $issueLocation[0];
      $columnnumber = $issueLocation[1];
      $issueCode = $issueCodeRegex.Matches($_)[0];
      $message = $messageRegex.Matches($_)[0];
    
      Write-Host "##vso[task.logissue type=$issueType;sourcepath=$sourcepath;linenumber=$linenumber;columnnumber=$columnnumber;code=$issueCode;]$message";
      if($issueType.Value -eq "error") { $hasErrors = $true; }
    };
    if($warnings.Count -gt 0 -and $hasErrors -eq $true) { Write-Host "##vso[task.complete result=Failed;]There are build errors"; } 
    elseif($warnings.Count -gt 0 -and $hasErrors -eq $false) { Write-Host "##vso[task.complete result=SucceededWithIssues;]There are build warnings"; } 
    

    image Update the Control Options: Run this task to Even if a previous task has failed, unless the build was cancelled to make sure that this script will run after a failing build which might be caused by CA errors. image

Printscreens

Logs tab when only having warnings:
image

Summary tab when only having warnings: image

Logs tab with errors: image

Summary tab with errors: image