'Azure Devops build throws error where localhost does not on .NET Core 2.2

I'm updating a backend of a website that's been running stable for the last 2 years. Some minor update has been asked which I got running on my localhost (about 5 lines of code update), but my devops build pipeline is throwing errors:

Package Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.2.0 is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). Package Microsoft.AspNetCore.Identity.EntityFrameworkCore 2.2.0 supports: netstandard2.0 (.NETStandard,Version=v2.0)
Package Microsoft.EntityFrameworkCore.SqlServer 2.2.4 is not compatible with netcoreapp2.2 (.NETCoreApp,Version=v2.2). Package Microsoft.EntityFrameworkCore.SqlServer 2.2.4 supports: netstandard2.0 (.NETStandard,Version=v2.0)
One or more packages are incompatible with .NETCoreApp,Version=v2.2.

I was expecting everything to work fine, considering I got it to work on my localhost.

I'm not too keen on updating everything to the latest version of .NET, because I really don't want to rewrite too much code that is working fine as is for an update of 5 lines of code.

Screenshot of the errors being thrown:

Errors thrown by devops builder

In the commit I also saw changes in storage.ide-shm and storage.ide-wal.

enter image description here

Looks like the fail happens because of the NuGet package restore during my build, which is triggered by a task in yml. My yml file I'm building my project:

# ASP.NET Core
# Build and test ASP.NET Core projects targeting .NET Core.
# Add steps that run tests, create a NuGet package, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

name: $(Build.SourceBranchName)_$(Date:yyyyMMdd)$(Rev:.r)

trigger:
- master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/myprojectname.API.csproj'
  buildConfiguration: 'Release'

steps:
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk'
  inputs:
    packageType: sdk
    version: 2.2.203
    installationPath: $(Agent.ToolsDirectory)/dotnet
    
    
- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/*.sln'
    feedsToUse: 'select'
    
- script: dotnet restore
- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(build.artifactstagingdirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    clean: true
- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact: drop'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)' 

How can I get the build to work again without having to upgrade to the latest version of .NET.



Solution 1:[1]

Azure Devops build throws error where localhost does not on .NET Core 2.2

This error can occur with an outdated version of nuget. Specifically, 4.0.0 exhibits this issue.

To resolve this issue, you could try to add nuget version installer task which you can run as part of your build step to upgrade the version of nuget running in your build pipeline:

- task: NuGetToolInstaller@1
  displayName: 'Use NuGet 6.1.0'
  inputs:
    versionSpec: 6.1.0
    checkLatest: true

Note: Add this task before the task nuget restore task.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leo Liu-MSFT