Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nuget restore fails with .NET Core SDK 5.0.100

I just updated a solution to use net50, and it builds locally, but does not build in an Azure pipeline. How do I specify an Azure pipeline agent capable of building net50 projects?


The pipeline fails on the nuget restore step with the following error:

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.

My pipeline yaml includes:

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'

like image 853
Eric Patrick Avatar asked Mar 01 '23 22:03

Eric Patrick


1 Answers

A workaround to using the NuGetCommand@2 step is to use the DotNetCoreCLI@2 step instead. This may not be viable if you are building legacy (non-SDK) projects.

My YAML is now:

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'

Thanks to @Krzysztof for pointing me in the right direction.

FWIW, and this is from memory, using DotNetCoreCLI@2 for a net48 project - which happened to be included in this pipeline's solution - failed under netcoreapp3.1, but appears to work under net50.

like image 155
Eric Patrick Avatar answered Mar 10 '23 11:03

Eric Patrick