DotNetCoreCLI@2 为什么只构建调试版本?

huangapple go评论87阅读模式
英文:

Why is DotNetCoreCLI@2 only building Debug builds?

问题

DotNetCoreCLI@2 只构建 Debug 版本的原因是什么?

在 Azure YAML 构建管道中,我有以下配置:

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/*.csproj'
    arguments: '-o $(Build.ArtifactStagingDirectory)/Output'
    zipAfterPublish: true
    modifyOutputPath: true

DotNetCoreCLI@2 任务直接来自文档

构建输出指示它正在构建 Debug 版本,为什么呢?

Starting: DotNetCoreCLI
==============================================================================
Task         : .NET Core
Description  : 构建、测试、打包或发布 dotnet 应用程序,或运行自定义 dotnet 命令
Version      : 2.221.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
Info: .NET Core SDK/runtime 2.2 和 3.0 已经到期 (EOL),并已从所有托管代理中移除。如果您在托管代理上使用这些 SDK/运行时,请升级到未到期的较新版本,或者使用 UseDotNet 任务安装所需版本。
/usr/bin/dotnet publish /home/vsts/work/1/s/AppServiceTerraform/AppServiceTerraform.csproj -o /home/vsts/work/1/a/Output/AppServiceTerraform
MSBuild 版本 17.6.3+07e294721 用于 .NET
  正在确定要还原的项目...
  已还原 /home/vsts/work/1/s/AppServiceTerraform/AppServiceTerraform.csproj(90 ms内)。
  AppServiceTerraform -> /home/vsts/work/1/s/AppServiceTerraform/bin/Debug/net6.0/AppServiceTerraform.dll
  AppServiceTerraform -> /home/vsts/work/1/a/Output/AppServiceTerraform/
Info: Azure Pipelines 托管代理已更新,现在包含 .Net 5.x SDK/Runtime 以及较旧的 .Net Core 版本,这些版本目前处于 lts 状态。除非您已锁定项目的 SDK 版本,否则可能会选择 5.x SDK,与以前的版本相比可能具有破坏性行为。您可以在此处了解有关破坏性更改的更多信息:https://docs.microsoft.com/en-us/dotnet/core/tools/ 和 https://docs.microsoft.com/en-us/dotnet/core/compatibility/。要了解更多此类更改并进行故障排除,请参阅此处:https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Finishing: DotNetCoreCLI

更新:在构建代理上运行 dotnet --info 报告:

Starting: Show Info
==============================================================================
Task         : PowerShell
Description  : 在 Linux、macOS 或 Windows 上运行 PowerShell 脚本
  6.0.411 [/usr/share/dotnet/sdk]
  7.0.108 [/usr/share/dotnet/sdk]
  7.0.203 [/usr/share/dotnet/sdk]
  7.0.305 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.19 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.19 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
Finishing: Show Info

更新:值得一提的是,我已经使用 Ildasm 检查了二进制文件,它们确实看起来是调试版本。

.custom instance void [System.Runtime]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 05 44 65 62 75 67 00 00 ) // ...Debug..
英文:

Why is DotNetCoreCLI@2 only building Debug builds?

In an Azure YAML build pipeline I have

trigger:
- main

pool:
  vmImage: 'ubuntu-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:

- task: DotNetCoreCLI@2
  inputs:
    command: 'publish'
    publishWebProjects: false
    projects: '**/*.csproj'
    arguments: '-o $(Build.ArtifactStagingDirectory)/Output'
    zipAfterPublish: true
    modifyOutputPath: true

The DotNetCoreCLI@2 task is taken directly from the documentation

The build output indicates it's building a debug build, why is that?

Starting: DotNetCoreCLI
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.221.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.
/usr/bin/dotnet publish /home/vsts/work/1/s/AppServiceTerraform/AppServiceTerraform.csproj -o /home/vsts/work/1/a/Output/AppServiceTerraform
MSBuild version 17.6.3+07e294721 for .NET
  Determining projects to restore...
  Restored /home/vsts/work/1/s/AppServiceTerraform/AppServiceTerraform.csproj (in 90 ms).
  AppServiceTerraform -> /home/vsts/work/1/s/AppServiceTerraform/bin/Debug/net6.0/AppServiceTerraform.dll
  AppServiceTerraform -> /home/vsts/work/1/a/Output/AppServiceTerraform/
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Finishing: DotNetCoreCLI

UPDATE Running dotnet --info on the build agent reports

Starting: Show Info
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script on Linux, macOS, or Windows
  6.0.411 [/usr/share/dotnet/sdk]
  7.0.108 [/usr/share/dotnet/sdk]
  7.0.203 [/usr/share/dotnet/sdk]
  7.0.305 [/usr/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.19 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.19 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
Finishing: Show Info

UPDATE For what it's worth I've examined the binaries in Ildasm and they do indeed appear to be debug binaries

.custom instance void [System.Runtime]System.Reflection.AssemblyConfigurationAttribute::.ctor(string) = ( 01 00 05 44 65 62 75 67 00 00 )                   // ...Debug..

答案1

得分: 3

你没有将构建配置传递给任务:

- task: DotNetCoreCLI@2
  inputs:
    configuration: '$(buildConfiguration)'
    ...

有一个文档注释指出,配置仅适用于 pack。我不确定具体原因,但你可能需要将打包和发布步骤拆分,以使用官方选项。

英文:

You're not passing the build configuration to the task:

- task: DotNetCoreCLI@2
  inputs:
    configuration: '$(buildConfiguration)'
    ...

There's a doc note that the configuration works with pack only. I wonder why exactly, but you may need to split the pack and publish steps to use the official options.

答案2

得分: 1

我需要在任务的 arguments 属性中明确指定配置。

DotNetCoreCLI@2 为什么只构建调试版本?

尽管我是通过 YAML 编辑器任务助手添加的任务,所以它会在 CI 流水线中执行 Debug 构建的状态下添加任务,但似乎没有明显的设置来解决这个问题,这看起来真的不太用户友好。

英文:

I needed to explicitly specify the configuration in the arguments property of the task.

DotNetCoreCLI@2 为什么只构建调试版本?

Although I added the task from the YAML editor task assistant, so it adding the task in a state that would perform a Debug build in a CI pipeline, and with no obvious setting to fix that seems really user unfriendly.

答案3

得分: 0

因此,正如注明的那样,这是由于 $(buildConfiguration) 没有被配置好,请参考此链接;然而,要配置它有两种方法。

一种方法是通过 UI 中的变量选项卡进行配置,但我个人不建议这样做,因为它与代码库分开。

另一种选择是将变量写入您的管道,类似于:

variables:
- name: buildConfiguration
  value: 'Release'

然后可以像这样使用:

- task: DotNetCoreCLI@2
  inputs:
    configuration: '${{ variables.buildConfiguration}}'

以这种方式进行配置还可以让您将 buildConfiguration 变量范围限定为作业,甚至更高级,作为包含各种环境信息的参数对象的属性。

还有一件事要确认或在故障排除中提供帮助,假设您不会使用运行时表达式,可以在完成后通过选择下载日志并打开 azuure-pipelines-expanded-yaml 来下载管道。这将显示整个管道以及适当的参数和变量展开... 除非它们被定义为运行时变量。

英文:

So as noted it is due to $(buildConfiguration) not being configured; however, to configure this there are two ways.

One is to do it via the UI in the variables tab, personally I don't recommend this as it is separate from the codebase.

The alternative would be write the variable into your pipeline similar to:

variables:
- name: buildConfiguration
  value: 'Release'

and then used like:

- task: DotNetCoreCLI@2
  inputs:
    configuration: '${{ variables.buildConfiguration}}'

Doing it this way will also let you to either set the buildConfiguration variable scoped by job or even more advanced as property of a parameter object containing your various environment information.

One other thing to confirm or assist in troubleshooting, assuming you won't use runtime expressions, can download the pipeline after completion by selecting download logs and open azuure-pipelines-expanded-yaml. This will show the entire pipeline with appropriate parameters and variables expanded...unless they are defined as runtime ones.

huangapple
  • 本文由 发表于 2023年7月3日 22:03:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76605516.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定