NuGet Package Manager: 'AutoMapper' already has a dependency defined for 'Microsoft.CSharp'

前端 未结 10 1646
迷失自我
迷失自我 2020-11-30 04:47

I\'m trying to add AutoMapper as a dependency to a project using NuGet on Visual Studio Premium 2012, but it fails.

It says:

Operation faile

相关标签:
10条回答
  • 2020-11-30 04:49

    Seems to be a problem with the current version of automapper:

    AutoMapper 5.0.0 Tuesday, June 28, 2016

    I tried with the previous version and it works:

    PM> Install-Package AutoMapper -Verbose
    Install-Package : 'AutoMapper' already has a dependency defined for 'Microsoft.CSharp'.
    At line:1 char:16
    + Install-Package <<<<  AutoMapper -Verbose
        + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
        + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
    
    PM> Install-Package AutoMapper -Version 4.2.1
    Installing 'AutoMapper 4.2.1'.
    Successfully installed 'AutoMapper 4.2.1'.
    

    So, if you can't update NuGet Package Manager, the answer is:

    PM> Install-Package AutoMapper -Version 4.2.1
    
    0 讨论(0)
  • 2020-11-30 04:49

    Automapper 6.0.2 - nuget 2.8.8 gives this error. Needed to update to 3.4.4 to get this working.

    0 讨论(0)
  • 2020-11-30 04:50

    An other workaround if you're stuck with VS2012 and the old Nuget version:

    • Find the Cache folder of VS 2012's Nuget Package Manager (with Tools - Options - Nuget Package Manager)
    • Open AutoMapper.5.x.x.nupkg with your favorite Zip Tool
    • Modify the file AutoMapper.nuspec - I simply deleted all dependencies except .NETFramework4.5
    • Add the cache folder as a Nuget source (also in Tools - Options - Nuget Package Manager)
    • Install Automapper either with the console or the GUI but make sure to choose first the newly added cache folder as package source.

    Of course, the next version of Automapper probably needs to be adapted, too, in order to install it.

    0 讨论(0)
  • 2020-11-30 04:51

    Go to Visual Studio > Tools > Extension and Updates

    Find Updates in left accordion menu, Go to Visual Studio Gallery.

    You will find a update for Nuget.

    Update the nuget package and try installing or builing the project.

    Thanks, GT

    0 讨论(0)
  • 2020-11-30 04:56

    The problem is that your NuGet Package Manager is too old. You need NuGet 2.12 since this supports the newer .NETStandard frameworks that the AutoMapper 5.0.1 NuGet package is using.

    The AutoMapper has a group dependency which specifies a target framework of .NETStandard. Since your version of NuGet Package Manager is too old it does not recognise this target framework and converts it to an Unknown target framework and you end up with duplicate frameworks since there .NETStandard is used a few times in that NuGet package. This causes the error:

    'AutoMapper' already has a dependency defined for 'Microsoft.CSharp'
    

    Unfortunately NuGet 2.12 is not available for Visual Studio 2012 but is available for Visual Studio 2013.

    So either you need to update to Visual Studio 2013 or above, or you will have to use the older AutoMapper NuGet package which does not support .NETStandard.

    0 讨论(0)
  • 2020-11-30 04:58

    I observed this exact problem when opening a project with Visual Studio 2010.

    After opening with VS2017, I was able to install AutoMapper without any error.

    0 讨论(0)
提交回复
热议问题