Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Restore task fails (not compatible with netcoreapp2.2), but it works in Visual Studio

I am trying to build a repository in Azure Pipelines. It builds OK in Visual Studio, but when using Azure Pipelines (with an agent running on a build machine), it fails with the following error:

The nuget command failed with exit code(1) and error

Project MyProject is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). 
Project MyProject supports: netstandard2.0 (.NETStandard,Version=v2.0)

How can I fix this?

And here is the yaml build script:

pool:
  name: MyBuildServer
  demands:
  - msbuild
  - visualstudio

steps:
- task: NuGetCommand@2
  displayName: 'NuGet restore'

- task: VSBuild@1
  displayName: 'Build solution **\*.sln'

- task: VSTest@2
  displayName: 'Run tests'
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
like image 488
Ola Eldøy Avatar asked Sep 19 '19 14:09

Ola Eldøy


1 Answers

NuGet Restore task fails (not compatible with netcoreapp2.2), but it works in Visual Studio

It seems that the version of nuget used on the Azure pipeline is not the latest version, which may cause the incompatibility issues.

To resolve this issue, you can try to add a NuGet Tool Installer task point it to a Version of NuGet.exe to install, which you simply specify the version number of the desired NuGet.exe you want to execute in the build.

enter image description here

Once this have been properly configured, the builds all succeeded using the latest incarnation of .net core.

Besides, if above not resolve your question, you can try to use the dotnet restore task instead of nuget restore task.

Hope this helps.

like image 161
Leo Liu-MSFT Avatar answered Oct 14 '22 05:10

Leo Liu-MSFT