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

时间:2019-08-09 11:26:56

标签: azure .net-core azure-devops blazor-server-side

是否可以使用azure-pipelines.yml在Azure DevOps上安装多个版本的.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 个答案:

答案 0 :(得分:3)

我对您的管道Yaml进行了测试,发现Azure任务DotNetCoreInstaller @ 0将覆盖以前安装的dotnet核心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'