Azure Devops dotnet build 不尊重配置

Azure Devops dotnet build don't respect configuration

在一个项目的 csproj 文件中,我有 TreatWarningsAsErrors 的条件。

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

在我的电脑上运行

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

产生了预期的成功和失败的不同结果。

然而,在我们的本地 azure devops 服务器上,即使日志清楚地指出“--Configuration Release”,它们也会将问题显示为警告。没有像预期的那样失败。

这里有什么问题吗?

构建日志摘录:

    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://docs.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\_work4\s\Modules\ScheduleMaker\Backend\ScheduleMaker.sln "-dl:CentralLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"*ForwardingLogger,\"F:\A\BUILDEDUI12C-B01\_work\_tasks\DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b.181.0\dotnet-build-helpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll\"" --configuration Release -p:CustomBeforeMicrosoftCommonTargets=F:\A\BUILDEDUI12C-B01\_work4\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.

编辑: 从诊断日志中我可以看到条件有效,它说它将变量更改为 True。

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

但事实并非如此。

要在 Azure Devops 中将其列为错误,解决方案是添加一个 属性,因此它看起来像这样:

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

然后设置在 Azure Devops 中被 属性 转发到。