1

In the csproj file of a project I have conditionals for TreatWarningsAsErrors.

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
  </PropertyGroup>

On my computer running

dotnet build solution.sln --Configuration Debug
vs
dotnet build solution.sln --Configuration Release

produces the different results with success and failure as expected.

On our on-prem azure devops server however, even though the log clearly states "--Configuration Release" they show the problems as Warnings. Not failures as expected.

What can be wrong here?

The build log excerpts:

    Starting: dotnet build
    ==============================================================================
    Task         : .NET Core
    Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
    Version      : 2.181.0
    Author       : Microsoft Corporation
    Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
    ==============================================================================
    C:\Windows\system32\chcp.com 65001
    Active code page: 65001
    Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
    F:\A\BUILDEDUI12C-B01\_work\_tool\dotnet\dotnet.exe build F:\A\BUILDEDUI12C-B01\_work\754\s\Modules\ScheduleMaker\Backend\ScheduleMaker.sln "-dl:CentralLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b\2.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --configuration Release -p:CustomBeforeMicrosoftCommonTargets=F:\A\BUILDEDUI12C-B01\_work\754\s\WE.CI.Tools.Build\Utilities\Education.SonarQube.ImportBefore.targets -p:SQProjectKey=WE.Education.ScheduleMaker
    Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET

[warning]Modules\ScheduleMaker\Backend\Service\WE.Education.ScheduleMaker.Business\Services\ActivityService.cs(61,13): Warning S125: Remove this commented out code.

Edit: From the diagnostics log i can see that the condition works, it says it changes the variable to True.

2022-04-14T07:06:33.6901214Z                    Property reassignment: $(TreatWarningsAsErrors)="True" (previous value: "false") at F:\A\BUILDEDUI12A-B01\_work\650\s\Modules\ScheduleMaker\Backend\Service\WE.Education.ScheduleMaker.Business\WE.Education.ScheduleMaker.Business.csproj (19,5)

But It dosen't act as it's true.

Leif Ershag
  • 146
  • 1
  • 15
  • well show some logs or a build pipeline or something - there is nothing to look at – sommmen Apr 14 '22 at 06:23
  • Added what's hopefully enough... It's... close to everything i see can affect it. – Leif Ershag Apr 14 '22 at 06:41
  • Well there seems nothing wrong with your build script if `--configuration Release` gets passed to dotnet new as it should, so... Perhaps enable ms build debugging and/or add some message tags to output the variable(s)?. (nice ms build log viewer here: https://msbuildlog.com/). – sommmen Apr 14 '22 at 06:49
  • Can you retest after replacing `Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"` with `Condition="'$(Configuration)'=='Debug'"` in your `.csproj`? – Robert Synoradzki Apr 14 '22 at 07:04
  • @RobertSynoradzki: Did that before this one with the same result. – Leif Ershag Apr 14 '22 at 09:29
  • No expert myself, but maybe you can use `.StartsWith` or `.Contains` as seen here: https://stackoverflow.com/q/10784740/1220550 – Peter B Apr 14 '22 at 09:36
  • It DOES recognice the condition, since i get this: 2022-04-14T07:06:33.6901214Z Property reassignment: $(TreatWarningsAsErrors)="True" (previous value: "false") at F:\A\BUILDEDUI12A-B01\_work\650\s\Modules\ScheduleMaker\Backend\Service\WE.Education.ScheduleMaker.Business\WE.Education.ScheduleMaker.Business.csproj (19,5) But how can it not... Be issuing errors. – Leif Ershag Apr 14 '22 at 12:03

1 Answers1

0

The solution, to get it listed as errors in Azure Devops was to add a property so it looked like this:

  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
    <TreatWarningsAsErrors>False</TreatWarningsAsErrors>
      <MSBuildTreatWarningsAsErrors>False</MSBuildTreatWarningsAsErrors>
  </PropertyGroup>
  
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <TreatWarningsAsErrors>True</TreatWarningsAsErrors>
      <MSBuildTreatWarningsAsErrors>true</MSBuildTreatWarningsAsErrors>
  </PropertyGroup>

Then the setting was property forwarded in Azure Devops to.

Leif Ershag
  • 146
  • 1
  • 15