如何在Azure DevOps上安装多个.NET Core SDK版本

11

在Azure DevOps上使用azure-pipelines.yml安装多个.NET Core SDK版本是否可能?如果可以,如何操作?

我正在尝试使用ElectronNET构建Blazor Server应用程序。 在我的本地计算机上,我可以轻松运行electronize build /target win。 但是,在Azure DevOps上运行构建时,会出现以下错误:

The specified framework 'Microsoft.NETCore.App', version '2.2.0' was not found.
  - The following frameworks were found:
      3.0.0-preview7-27912-14 at [/opt/hostedtoolcache/dotnet/shared/Microsoft.NETCore.App]

我的 azure-pipelines.yml 长这个样子:

trigger:
- master

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: DotNetCoreInstaller@0
  displayName: Install .NET Core 2.2 SDK
  inputs:
    packageType: 'sdk'
    version: '2.2.401'

- script: |
    dotnet tool install ElectronNET.CLI -g
  displayName: 'Install global tool ElectronNET.CLI'

- task: DotNetCoreInstaller@0
  displayName: Install Latest .NET Core 3.0 SDK
  inputs:
    packageType: 'sdk'
    version: '3.0.100-preview7-012821'

- script: |
    cd MyProject
    electronize build /target win
  displayName: 'Build Windows app with ElectronNET'
1个回答

12

我使用您的管道yaml进行测试,发现Azure任务DotNetCoreInstaller@0将覆盖先前安装的dotnet core sdk。我用任务UseDotNet@2替换了DotNetCoreInstaller@0以安装两个版本的dotnet core sdks,错误消失了。

steps:
- task: UseDotNet@2
  displayName: Install .NET Core 2.2 SDK
  inputs:
    packageType: 'sdk'
    version: '2.2.401'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接