Azure Devops - 托管池 - ubuntu latest - 我如何获得 ubuntu-latest 以获得最新的 visual studio 构建工具(预览版 2022)?

Azure Devops - Hosted pool - ubuntu latest - How do i get ubuntu-latest to have the latest visual studio build tools (preview 2022)?

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

我正在使用需要包的 Azure Functions: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.**

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

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

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 

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

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

解释一下,首先 Visual Studio 只在 Windows 上运行,所以你不能在 Linux 上安装 Visual Studio,但这没关系,因为你实际上只想要.NET 开发工具包。其次,Visual Studio 2022 和 .NET 6 都处于预览状态。

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

如果您按照 link 到 .NET Core SDK on Ubuntu 20.04 (latest),您会发现它们仅预安装 .NET SDK 的一般可用(GA;已发布)版本,而不是预览版本。毕竟,大多数构建生产应用程序的客户都不希望冒着使用可能存在错误并破坏其构建的预览工具的风险。

因此,如果您需要预览版 .NET SDK,则需要在构建步骤中明确安装它。 UseDotNet task 这样做,允许您指定一堆参数,但在这种情况下,最重要的两个是版本,包括预览版本。

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

物有所值,.NET 6 is having a launch party on the 9th to the 11th of November, and Visual Studio 2022 is having a launch event on the 8th of November。我不知道 Azure DevOps 将以多快的速度使用新发布的工具更新他们的 VM 映像,但我想这将在几天内完成,因此在构建脚本中安装预览工具的时间不会太长,除非你想继续使用预览工具。请注意,一旦 .NET 6 SDK 的 6.0.100 正式发布,安装预览版 6.0.x 工具的脚本将开始安装预览版 6.0.200 previews