我使用了一些.csproj
特性:
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
在当地,这一切都很好。
- 引起警告,它不会建立
- 以非标准方式格式化某个内容,它将无法构建
问题在于:它在本地构建得很好,但Azure DevOps失败了,引用IDE0055中关于链接方法的内联注解:
var list = new List<string>();
var cleanList = list
// ignore zero-length strings
.Where(l => l.Length == 0)
// ignore too-long strings
.Where(l => l.Length > 10)
.ToList();
有两个不同之处:
1.本地:Windows和MSBuild version 17.4.0+18d5aef85 for .NET
1.开发运维:Linux和Build Engine version 17.1.1+a02f73656 for .NET
**我想应该是这个过时的(?)构建引擎造成的。有没有办法针对不同的构建引擎?**希望它不绑定到UseDotNet@2 packageType
,因为它需要设置为6.0.202
,这样代码才能在AWS Lambda上运行。
完整的DevOps输出:
Starting: Build projects
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.210.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
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.
/opt/hostedtoolcache/dotnet/dotnet build /home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" -c Release -r linux-x64 -p:PublishReadyToRun=true
Microsoft (R) Build Engine version 17.1.1+a02f73656 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
Restored /home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj (in 367 ms).
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(22,33): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(22,33): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(23,46): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(23,46): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(24,43): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(24,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
##[error]Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(25,43): Error IDE0055: Fix formatting
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(25,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
Build FAILED.
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(22,33): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(23,46): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(24,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/AdjustEmployeeScheduleRequest.cs(25,43): error IDE0055: Fix formatting [/home/vsts/work/1/s/Psrm.ScheduleCalculator.Contract/Psrm.ScheduleCalculator.Contract.csproj]
0 Warning(s)
4 Error(s)
Time Elapsed 00:00:03.50
##[error]Error: The process '/opt/hostedtoolcache/dotnet/dotnet' failed with exit code 1
/opt/hostedtoolcache/dotnet/dotnet build /home/vsts/work/1/s/Psrm.ScheduleCalculator.InternalContract/Psrm.ScheduleCalculator.InternalContract.csproj -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.210.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" -c Release -r linux-x64 -p:PublishReadyToRun=true
1条答案
按热度按时间omhiaaxx1#
根据您的描述,问题似乎与运行构建的不同操作系统(Windows和Linux)有关。
因为您是在本机Windows计算机上开发和编辑C#程式码,所以当您直接在本机Windows计算机上建置程式码时,它可以符合一致的程式码样式。
但是,当您转到Linux机器上进行构建时,对于缩进、空格和新行如何围绕.NET编程语言结构对齐,它可能与Windows不同。
有关IDE0055错误的详细信息,请参阅文档“Formatting rule (IDE0055)“。
对于您的情况,您可以尝试选择Windows代理在Azure DevOps上运行生成管道。我们已经为Azure DevOps上的Azure管道提供了Microsoft托管的Windows代理(
windows-2022
和windows-2019
)。或者,您可以在本地Windows计算机上设置self-hosted agent来运行生成管道。