azure-pipelines-tasks: dotnet build doesn't capture warnings

Environment

  • Server - VSTS or TFS on-premises? VSTS

  • Agent - Hosted or Private: Private

Issue Description

We have a .NET Core task which is running a build command. The build is showing warnings in Visual Studio when built locally and also in the logs when being built by VSTS. These are not captured by VSTS and so are not displayed in the build UI.

2018-07-11T14:03:44.2237927Z C:\Program Files\dotnet\sdk\2.1.301\Microsoft.Common.CurrentVersion.targets(2106,5): warning MSB3277: Found conflicts between different versions of "Microsoft.AspNetCore.Hosting" that could not be resolved.  These reference conflicts are listed in the build log when log verbosity is set to detailed. [D:\VSTS Agent\_work\23\s\YorkshireWater.LeakageAPI\YorkshireWater.LeakageAPI.Tests\YorkshireWater.LeakageAPI.Tests.csproj]

I believe this is because the command is not using the ##[warning] syntax used by the equivalent Visual Studio build tasks (see example below). Since this is a task for the dotnet command, it should be able to capture the warning messages which it uses.

2018-07-17T08:53:19.6614622Z ##[warning]CSC(0,0): Warning CS8032: An instance of analyzer Microsoft.EntityFrameworkCore.RawSqlStringInjectionDiagnosticAnalyzer cannot be created from C:\Users\svcbuildservervsts\.nuget\packages\microsoft.entityframeworkcore.analyzers\2.1.1\analyzers\dotnet\cs\Microsoft.EntityFrameworkCore.Analyzers.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=2.8.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 33
  • Comments: 23 (4 by maintainers)

Most upvoted comments

This is still an issue in Azure DevOps over a year later (no errors or warnings reported in the Azure DevOps build). IMO there really needs to be a custom msbuild logger used in “dotnet build” which reports errors in the required format.

Thanks for feedback folks. We will plan to start this work in 2-3 weeks time.

Why reporting DotNetCoreCLI warnings as Azure DevOps warnings was added only to the build command? What about some other commands like restore or publish? Why not give user option via task input to specify whether they want to capture warnings for this task regardless of command used?

Before we had restore -> build -> publish flow via DotNetCoreCLI tasks and warnings from build were reported. We simplified pipeline to restore -> publish, as publish is going to build anyways, but now all warnings are gone from Azure DevOps 🤣

Issue regarding publish command is also reported here: https://github.com/microsoft/azure-pipelines-tasks/issues/18380

I would expect DotNetCoreCLI to support reporting warnings as Azure DevOps warnings regardless of command used.

It looks like this behavior was recently addressed with the release of #12358 in version 2.166.1 of the .NET Core Azure DevOps build task. That task now additionally logs warnings in a line with a ##[warning] prefix. This caught us by surprise because several of our builds have warnings that had gone undetected. After v2.166.1 of the DotNetCoreCLIV2 task was released to our Azure DevOps pipelines, our Check build warnings task (Build Quality Checks) started failing for those builds.

Note also that many of these workarounds don’t work on Linux - as far as I recall, the msbuild task doesn’t work correctly on Linux (eg Ubuntu 16.04), b/c the msbuild version resolution is different, and invoking it is different. This is part of the reason why we need an MSBuild logger that writes pipelines output out of the box.

Also, a design suggestion: I think it would be super useful to have a separate nuget package for a dotnet core compatible Azure pipelines msbuild logger. There are a lot of other situations where it could be used (eg when running a cake build in pipelines, and cake calls dotnet build, so would have to pass in the right arguments to use the pipelines logger).

I’ve thought about writing and sharing my own, but this seems like something Microsoft would/should own… And of course they already have one (referenced from the msbuild task), but it’s not shared in source code form or on nuget.

We will pick this up as an enhancement to the task in the next sprint planning. Thanks for the feedback!! Atul

@bishal-pdMSFT not sure I follow properly on (or simply understand) how the NuGet package will solve this issue for Docker task.

Multi-stage build within Dockerfile is now encouraged, even in default aspnetcore template. So having Docker task picking up the warning properly in that case seem like a reasonable ask as it only follows guidelines enforced by Microsoft itself…

I did not realize that this issue was still open. As @Blackbaud-TommyVernieri commented above the fix is already done via PR https://github.com/microsoft/azure-pipelines-tasks/pull/12358/files

Regarding the ask for a nuget package so that it can be used outside of ADO, I think this repo is not the right target for such ask as it only tracks task issues. May be a better place is to start with .Net Core team on what they think about this.

Hence I am closing this issue.

I have a build script based on bullseye that manually calls into MSBuild. That allows us to trigger builds manually, independent of Azure DevOps.

Having this logger available would be extremely useful for us tho, so our PR build validation errors show up properly in Azure Pipelines.

I wonder if you could also support it out of the .NET Core azure devops task (by providing some nuget package). Some people call dotnet build from powershell or docker file. It would be nice to have nice experience while using this tools too

@bishal-pdMSFT Any updates on this one?

I created a (ugly) workaround which can be used to show the build warnings in the Log and Summary tab in Azure Devops. I only tested this azure-pipelines.yml for .NET Core 2.2.102. But feel free to try it out: https://github.com/melisco/azure-devops-dotnet-warnings

You can also work around this by using the “Warning Filters” regular expression. e.g. /\s(\d+)\s+warning/i

This also matches “0 Warning(s)”. I think this should do the trick:

/\s([1-9]\d*\.?[0]*)\s+Warning\(s\)|\s([1-9]\d*\.?[0]*)\s+Error\(s\)/

You can also work around this by using the “Warning Filters” regular expression. e.g. /\s(\d+)\s+warning/i