'Azure DevOps Pipeline error "Package (...) is not compatible with net60"

I have source control and pipelines in Azure Devops.

My project has two target frameworks: 3.1 and 6.

While running the pipeline, it throws errors when restoring packages:

##[error]The nuget command failed with exit code(1) and error(Errors in D:\a\1\s\nuget-tst\src\nuget-tst.csproj Package Microsoft.Extensions.Configuration.Json 3.1.3 is not compatible with net60 (.NETFramework,Version=v6.0). Package Microsoft.Extensions.Configuration.Json 3.1.3 supports: - netcoreapp3.1 (.NETCoreApp,Version=v3.1) - netstandard2.0 (.NETStandard,Version=v2.0) Package Microsoft.Extensions.Configuration.FileExtensions 3.1.3 is not compatible with net60 (.NETFramework,Version=v6.0). Package Microsoft.Extensions.Configuration.FileExtensions 3.1.3 supports: - netcoreapp3.1 (.NETCoreApp,Version=v3.1) - netstandard2.0 (.NETStandard,Version=v2.0) Package Microsoft.Extensions.Configuration.EnvironmentVariables 3.1.3 is not compatible with net60 (.NETFramework,Version=v6.0). Package Microsoft.Extensions.Configuration.EnvironmentVariables 3.1.3 supports: - netcoreapp3.1 (.NETCoreApp,Version=v3.1) - netstandard2.0 (.NETStandard,Version=v2.0) One or more packages are incompatible with .NETFramework,Version=v6.0. Package Microsoft.IdentityModel.Tokens 6.5.0 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.IdentityModel.Tokens 6.5.0 supports: - net45 (.NETFramework,Version=v4.5) - net461 (.NETFramework,Version=v4.6.1) - netstandard2.0 (.NETStandard,Version=v2.0) Package Microsoft.Extensions.FileSystemGlobbing 3.1.3 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Package Microsoft.Extensions.FileSystemGlobbing 3.1.3 supports: netstandard2.0 (.NETStandard,Version=v2.0) One or more packages are incompatible with .NETCoreApp,Version=v3.1.) ##[error]Packages failed to restore

The azure pipelines yaml:

    trigger:
  branches:
      include:
      - master

pr:
- master
- develop

pool:
  vmImage: 'windows-latest'

variables:
  solution: '*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  major: 1
  minor: 0

name: $(major).$(minor)$(Rev:.r)

stages:

# Versioning master branch builds

- stage:
  displayName: Build_Master_Version_Number
  condition: eq(variables['Build.SourceBranch'], 'refs/heads/master')
  jobs:
  - job: Build_Master_Version_Number
    variables:
       patch: $[counter(variables['minor'], 0)]
    steps:
      - bash: |
           echo "##vso[build.updatebuildnumber]$(major).$(minor).$(patch)"
        name: SetMasterBuildName

# Versioning feature branch and PR builds

- stage:
  displayName: Build_Branch_Version_Number
  condition: ne(variables['Build.SourceBranch'], 'refs/heads/master')
  jobs:
  - job: Build_Branch_Version_Number
    variables:
       prpatch: $[counter(variables['system.pullrequest.pullrequestid'], 0)]
       brpatch: $[counter(variables['build.sourcebranchname'], 0)]
    steps:
      - bash: |
           echo "##vso[build.updatebuildnumber]$(major).$(minor)-PullRequest.$(prpatch)"
        condition: eq(variables['Build.Reason'], 'PullRequest')
        name: SetPRBuildName
      - bash: |
           echo "##vso[build.updatebuildnumber]$(major).$(minor)-$(Build.SourceBranchName).$(brpatch)"
        condition: ne(variables['Build.Reason'], 'PullRequest')
        name: SetBranchBuildName

# Stage for building your application

- stage: Build_Steps
  displayName: Build_Steps
  condition: always()
  jobs:  
  - job: Build_Steps
    displayName: Build_Steps

    steps:

    - task: UseDotNet@2
      displayName: 'Use .NET Core SDK 3.1.200'
      inputs:
        packageType: sdk
        version: 3.1.200

    - task: UseDotNet@2
      displayName: 'Install .NET 6 SDK'
      inputs:
        packageType: 'sdk'
        version: '6.0.x'
        performMultiLevelLookup: true

    - task: NuGetCommand@2
      displayName: 'Restore packages'
      inputs:
        command: 'restore'

    - task: DotNetCoreCLI@2
      displayName: 'Build solution'
      inputs:
        command: 'build'
        arguments: '--configuration $(buildConfiguration) --no-restore /p:Version=$(Build.BuildNumber)'
        projects: '$(solution)'
    
    - task: DotNetCoreCLI@2  
      displayName: 'Pack packages'
      inputs:
        command: 'pack'
        versioningScheme: byBuildNumber
        arguments: '--configuration $(buildConfiguration)'
        packagesToPack: '**/*.csproj'
        nobuild: true
        packDestination: '$(Build.ArtifactStagingDirectory)'
    
    - task: NuGetCommand@2
      displayName: "Publish to Nuget Feed"
      inputs:
        command: 'push'
        feedsToUse: 'select'
        packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg'
        vstsFeed: 'nugetfeeds/Dev'
        publishVstsFeed: 'nugetfeeds/Dev'
    

The only way I found out to overcome was to set vmImage to 'windows-2019' but that seems odd to me. Why shouldn't it work with latest version (windows-latest)?



Solution 1:[1]

something similar happened to me. Solved it by adding a nuget tool installer task before the nuget restore step:

 - task: NuGetToolInstaller@1
  inputs:
    versionSpec: 
    checkLatest: true

Before adding this step, the nuget tool version was very old (see this line from the output logs of the nuget restore task)

Caching tool: NuGet 5.4.0 x64

After this modification, the same log shows this:

Detected NuGet version 6.1.0.106 / 6.1.0 ...

I go the idea from here: Dotnet github issues

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 Julio Cachay