'Problem in Azure DevOps pipeline restoring AutoMapper NuGet package in .net 6

I get the following error message when my pipeline is being run:

Package AutoMapper.Extensions.Microsoft.DependencyInjection 8.1.1 is not compatible with net60 (.NETFramework,Version=v6.0). Package AutoMapper.Extensions.Microsoft.DependencyInjection 8.1.1 supports: netstandard2.0 (.NETStandard,Version=v2.0) One or more packages are incompatible with .NETFramework,Version=v6.0.)

Is there something I can do here or do I need to wait for the AutoMapper team to update it?



Solution 1:[1]

It looks like the error in my case has nothing to do with Automapper. I had to create a completely new pipeline which fixed my issues.

Solution 2:[2]

After some research, I decided to replace the NuGetCommand (NuGet-Task) with the DotNetCoreCli "restore" task. First I had to switch the "vmImage" from "windows-latest" to "windows-2022" as it seems the latest one has a grace period of a few months (read more here). Just before that, I had many more of those "is not compatible with net60" errors. Not just from AutoMapper.

Here is my Azure DevOps Pipeline YAML for all that had the same struggle to migrate their pipeline to .NET 6 as a starting point.

trigger:
  batch: true
  branches:
    include:
    - main

stages:
- stage: Build_Release
  pool:
    vmImage: windows-2022
  jobs:
  - job: Build
    variables:
      buildConfiguration: 'Release'
      solution: './SomeSolution.Name.sln'
    continueOnError: false
    steps:
 
    - task: DotNetCoreCLI@2
      inputs:
        command: 'restore'
        feedsToUse: 'config'
        nugetConfigPath: '.\NuGet.config'
        externalFeedCredentials: 'Telerik NuGet Connection'

    - task: VSBuild@1
      displayName: 'Build Solution'
      inputs:
        solution: '$(solution)'
        msbuildArgs: '/p:DeployOnBuild=true /p:PublishProvider=FileSystem /p:ExcludeApp_Data=False /p:DeleteExistingFiles=True /p:PublishUrl=$(Build.ArtifactStagingDirectory) /p:Configuration=$(buildConfiguration)'
        configuration: '$(buildConfiguration)'
        maximumCpuCount: true
        createLogFile: true

    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifacts'
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'some-artifact-name'
        publishLocation: 'Container'

Edit: Removed the UseDotNet-Task as it seems not to be required when using windows-2022. Link

Solution 3:[3]

I have the same error and fixed them updated nuget version packet to 6.2.0 in pipeline

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 Ægir Örn Sveinsson
Solution 2
Solution 3 Juan Rodriguez