繁体   English   中英

Azure Devops do.net 构建不尊重配置

[英]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://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.

编辑:从诊断日志中我可以看到条件有效,它说它将变量更改为 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)

但它并没有像真的那样行事。

要将其列为 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 中被转发到。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM