首页 > 解决方案 > .NET Core SDK 5.0.100 的 Nuget 还原失败

问题描述

我刚刚更新了一个要使用的解决方案net50,它在本地构建,但不在 Azure 管道中构建。如何指定能够构建net50项目的 Azure 管道代理?


管道在该nuget restore步骤上失败,并出现以下错误:

The nuget command failed with exit code(1) and error([***].csproj : error : 
Version 5.0.100 of the .NET Core SDK requires at least version 16.8.0 of MSBuild. 
The current available version of MSBuild is 16.7.0.37604. 
Change the .NET Core SDK specified in global.json to an older version that requires the MSBuild version currently available.

我的管道 yaml 包括:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Debug'

steps:

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 5.x
    installationPath: $(Agent.ToolsDirectory)/dotnet

- task: NuGetCommand@2
  displayName: 'nuget restore'
  inputs:
    restoreSolution: '**/*.sln'
    feedsToUse: config
    nugetConfigPath: 'NuGet.config'

标签: azure-devopsmsbuildnuget.net-5

解决方案


使用该步骤的解决方法NuGetCommand@2是改用该DotNetCoreCLI@2步骤。如果您正在构建遗留(非 SDK)项目,这可能不可行。

我的 YAML 现在是:

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  buildConfiguration: 'Debug'

steps:

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 5.x
    installationPath: $(Agent.ToolsDirectory)/dotnet

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'config'
    nugetConfigPath: 'nuget.config'

感谢@Krzysztof 为我指明了正确的方向。

FWIW,这是来自内存,DotNetCoreCLI@2用于一个net48项目 - 该项目恰好包含在此管道的解决方案中 -netcoreapp3.1net50.


推荐阅读