6

我们的 azure devops 管道配置为使用托管的 ubuntu-latest

vmImage:'ubuntu-最新的'

我正在使用需要包的 Azure 函数:packages/microsoft.net.sdk.functions/4.0.0 托管的 ubuntu 最新版本抛出不兼容的框架版本错误。

 /home/vsts/.nuget/packages/microsoft.net.sdk.functions/4.0.0/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5):
 error : It was not possible to find any compatible framework version 
 /home/vsts/.nuget/packages/microsoft.net.sdk.functions/4.0.0/build/Microsoft.NET.Sdk.Functions.Build.targets(32,5):
 error : The framework 'Microsoft.NETCore.App', version
 '6.0.0-rc.1.21451.13' was not found.**

Azure devops 错误图像

将池更改为在本地构建代理上运行时,我能够安装最新的构建工具(Visual Studio 2022 预览版随附的工具)并且一切正常。 我的问题是如何让 ubuntu-latest 拥有最新的 dotnet 构建工具?

这是ubuntu-latest 代理的dotnet info的输出。

2021-10-27T04:54:16.4629465Z .NET SDKs installed:
2021-10-27T04:54:16.4630372Z   2.1.302 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4630865Z   2.1.403 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4631327Z   2.1.526 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4631821Z   2.1.617 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4632292Z   2.1.701 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4632746Z   2.1.818 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4633218Z   3.1.120 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4633687Z   3.1.202 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4634147Z   3.1.302 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4634616Z   3.1.414 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4635086Z   5.0.104 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4635541Z   5.0.208 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4636008Z   5.0.303 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4636462Z   5.0.402 [/usr/share/dotnet/sdk]
2021-10-27T04:54:16.4636703Z 
2021-10-27T04:54:16.4637082Z .NET runtimes installed:
2021-10-27T04:54:16.4637683Z   Microsoft.AspNetCore.All 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
2021-10-27T04:54:16.4638405Z   Microsoft.AspNetCore.All 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
2021-10-27T04:54:16.4639112Z   Microsoft.AspNetCore.All 2.1.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
2021-10-27T04:54:16.4639839Z   Microsoft.AspNetCore.All 2.1.24 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
2021-10-27T04:54:16.4640553Z   Microsoft.AspNetCore.All 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.All]
2021-10-27T04:54:16.4641691Z   Microsoft.AspNetCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4642420Z   Microsoft.AspNetCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4643130Z   Microsoft.AspNetCore.App 2.1.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4643823Z   Microsoft.AspNetCore.App 2.1.24 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4644541Z   Microsoft.AspNetCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4645263Z   Microsoft.AspNetCore.App 3.1.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4645958Z   Microsoft.AspNetCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4646889Z   Microsoft.AspNetCore.App 3.1.20 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4647598Z   Microsoft.AspNetCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4648286Z   Microsoft.AspNetCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4648995Z   Microsoft.AspNetCore.App 5.0.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
2021-10-27T04:54:16.4649693Z   Microsoft.NETCore.App 2.1.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4650357Z   Microsoft.NETCore.App 2.1.5 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4651045Z   Microsoft.NETCore.App 2.1.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4651737Z   Microsoft.NETCore.App 2.1.24 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4652407Z   Microsoft.NETCore.App 2.1.30 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4653101Z   Microsoft.NETCore.App 3.1.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4653781Z   Microsoft.NETCore.App 3.1.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4654445Z   Microsoft.NETCore.App 3.1.20 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4655124Z   Microsoft.NETCore.App 5.0.4 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4655799Z   Microsoft.NETCore.App 5.0.9 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4656459Z   Microsoft.NETCore.App 5.0.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2021-10-27T04:54:16.4656807Z 
4

1 回答 1

11

在您的管道定义中使用它:

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    version: 6.0.x
    includePreviewVersions: true

解释一下,首先 Visual Studio 只能在 Windows 上运行,所以你不能在 Linux 上安装 Visual Studio,但这很好,因为你实际上只需要 .NET SDK。其次,Visual Studio 2022 和 .NET 6 都处于预览阶段。

接下来,Azure DevOps 记录了所有托管代理上预装了哪些软件:https ://docs.microsoft.com/en-us/azure/devops/pipelines/agents/hosted?view=azure-devops&tabs=yaml#软件

如果您点击Ubuntu 20.04 (latest) 上的 .NET Core SDK链接,您会看到它们仅预安装了 .NET SDK 的普遍可用(GA;已发布)版本,而不是预览版本。毕竟,大多数构建其生产应用程序的客户不希望冒使用可能存在错误和破坏其构建的预览工具的风险。

因此,如果您想要一个预览版 .NET SDK,您需要在构建步骤中显式安装它。UseDotNet 任务执行此操作,允许您指定一堆参数,但在这种情况下,最重要的两个是版本和包含预览版本。

对于其他场景,例如不使用 Azure Pipelines 的任何人,.NET 团队也有dotnet-install 脚本,您可以下载并在您的管道中执行。

值得一提的是,.NET 6 将于 11 月 9 日至 11 日举行发布会,Visual Studio 2022 将于 11 月 8 日举行发布会。我不知道 Azure DevOps 会以多快的速度使用新发布的工具更新他们的 VM 映像,但我想它会在几天内完成,因此在构建脚本中安装预览工具的时间将不再需要,除非你想继续使用预览工具。请注意,一旦 .NET 6 SDK 的 6.0.100 正式发布,安装预览版 6.0.x 工具的脚本将开始安装预览版 6.0.200 预览版

于 2021-11-05T13:59:27.473 回答