installing nuget package “same key has already been added.”

后端 未结 12 1371
太阳男子
太阳男子 2020-12-10 00:38

i am trying to install Microsoft.Bcl.Build 1.0.14

nuget returns

Installing \'Microsoft.Bcl.Build 1.0.14\'. Successfully installed \'Microsoft.Bcl.Bu         


        
相关标签:
12条回答
  • 2020-12-10 01:10

    I was facing the same problem while Building a project in c#.

    System.ArgumentException: An item with the same key has already been added.
         at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
         at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
         at System.IO.Packaging.ZipPackage.ContentTypeHelper.ProcessDefaultTagAttributes(XmlTextReader reader)
         at System.IO.Packaging.ZipPackage.ContentTypeHelper.ParseContentTypesFile(ZipFileInfoCollection zipFiles)
         at System.IO.Packaging.ZipPackage.ContentTypeHelper..ctor(ZipArchive zipArchive, IgnoredItemHelper ignoredItemHelper)
         at System.IO.Packaging.ZipPackage..ctor(Stream s, FileMode mode, FileAccess access, Boolean streaming)
         at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)
         at System.IO.Packaging.Package.Open(Stream stream)
         at NuGet.PackageHelper.GetManifestStream(Stream packageStream)
         at NuGet.OptimizedZipPackage.EnsureManifest()
         at NuGet.OptimizedZipPackage..ctor(String fullPackagePath)
         at NuGet.CommandLine.PackCommand.PrintVerbose(String outputPath)
         at NuGet.CommandLine.PackCommand.BuildPackage(PackageBuilder builder, String outputPath)
         at NuGet.CommandLine.PackCommand.BuildFromNuspec(String path)
         at NuGet.CommandLine.PackCommand.BuildPackage(String path)
         at NuGet.CommandLine.PackCommand.ExecuteCommand()
         at NuGet.CommandLine.Command.ExecuteCommandAsync()
         at NuGet.CommandLine.Command.Execute()
         at NuGet.CommandLine.Program.MainCore(String workingDirectory, String[] args)
    

    Found that multiple Nuget .spec files were present in bin\Debug folder.

    0 讨论(0)
  • 2020-12-10 01:17

    In my case I ran a dotnet restore from the package manager console to get the duplicated key

    PM> dotnet restore
      Determining projects to restore...
    C:\Program Files\dotnet\sdk\3.1.300\NuGet.targets(128,5): error : An item with the same key has already been added. Key: (XXXX.XXX.XX, 1.0.0.0-preview1) [C:\code\MySolution.sln]
    
    0 讨论(0)
  • 2020-12-10 01:18

    Looks like NuGet is finding a duplicate Portable Class Library (PCL) profile on your machine. It is shame the key is not logged in the exception callstack which would make things easy.

    You could try Jon Skeet's PclPal program which can list the PCL profiles and see if there's anything duplicated.

    I have another MonoPcl program that does a similar thing. It refers to Mono but works on Windows. It uses the NuGet source code so it will have the same problem as you are seeing in Visual Studio. However you should be able to modify the code to catch the exception or put some extra logging to see what the duplicate PCL profile is that is causing the problem.

    0 讨论(0)
  • 2020-12-10 01:22

    Your stack-trace tells the tale, it is NuGet.NetPortableProfileTable.BuildPortableProfileCollection() that fails. In a nutshell, it iterates the set of PCL reference assembly profiles and encounters the same profile more than once. This is a very strong hint that the content of your c:\program files (x86)\reference assemblies\microsoft\framework\.netportable directory is corrupted.

    There are many possible ways to go about fixing the damage:

    • If you have an active recollection of tinkering with this directory, like copying files, then undo what you did.
    • Safest way to go about it is to uninstall all Visual Studio versions >= VS2010. Then clean up the directory by hand, deleting any stray files that are still present. Then reinstalling VS again.
    • The not-so-safe but speedier way is to rename the c:\program files (x86)\reference assemblies directory and install the multi-targeting pack. I can't promise success.
    • You can try to find the duplicate yourself and remove it. The directory structure looks like this:

     Directory of C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.0\Profile
    
    05/14/2014  01:01 PM    <DIR>          Profile1
    05/14/2014  01:01 PM    <DIR>          Profile102
    05/14/2014  01:01 PM    <DIR>          Profile104
    05/14/2014  01:01 PM    <DIR>          Profile131
    05/14/2014  01:01 PM    <DIR>          Profile136
    05/14/2014  01:01 PM    <DIR>          Profile14
    05/14/2014  01:01 PM    <DIR>          Profile143
    05/14/2014  01:01 PM    <DIR>          Profile147
    05/14/2014  01:01 PM    <DIR>          Profile154
    05/14/2014  01:01 PM    <DIR>          Profile158
    05/14/2014  01:01 PM    <DIR>          Profile18
    05/14/2014  01:01 PM    <DIR>          Profile19
    05/14/2014  01:01 PM    <DIR>          Profile2
    05/14/2014  01:01 PM    <DIR>          Profile225
    05/14/2014  01:01 PM    <DIR>          Profile23
    05/14/2014  01:01 PM    <DIR>          Profile24
    05/14/2014  01:01 PM    <DIR>          Profile240
    05/14/2014  01:01 PM    <DIR>          Profile255
    05/14/2014  01:01 PM    <DIR>          Profile3
    05/14/2014  01:01 PM    <DIR>          Profile328
    05/14/2014  01:01 PM    <DIR>          Profile336
    05/14/2014  01:01 PM    <DIR>          Profile344
    05/14/2014  01:01 PM    <DIR>          Profile36
    05/14/2014  01:01 PM    <DIR>          Profile37
    05/14/2014  01:01 PM    <DIR>          Profile4
    05/14/2014  01:01 PM    <DIR>          Profile41
    05/14/2014  01:01 PM    <DIR>          Profile42
    05/14/2014  01:01 PM    <DIR>          Profile46
    05/14/2014  01:01 PM    <DIR>          Profile47
    05/14/2014  01:01 PM    <DIR>          Profile5
    05/14/2014  01:01 PM    <DIR>          Profile6
    05/14/2014  01:01 PM    <DIR>          Profile88
    05/14/2014  01:01 PM    <DIR>          Profile92
    05/14/2014  01:01 PM    <DIR>          Profile95
    05/14/2014  01:01 PM    <DIR>          Profile96
    
     Directory of C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile
    
    05/14/2014  12:59 PM    <DIR>          .
    05/14/2014  12:59 PM    <DIR>          ..
    05/14/2014  01:01 PM    <DIR>          Profile111
    05/14/2014  01:01 PM    <DIR>          Profile259
    05/14/2014  01:01 PM    <DIR>          Profile49
    05/14/2014  01:01 PM    <DIR>          Profile7
    05/14/2014  01:01 PM    <DIR>          Profile78
    
     Directory of C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.6\Profile
    
    05/14/2014  12:59 PM    <DIR>          .
    05/14/2014  12:59 PM    <DIR>          ..
    05/14/2014  01:01 PM    <DIR>          Profile151
    05/14/2014  01:01 PM    <DIR>          Profile157
    05/14/2014  01:01 PM    <DIR>          Profile31
    05/14/2014  01:01 PM    <DIR>          Profile32
    05/14/2014  01:01 PM    <DIR>          Profile44
    05/14/2014  01:01 PM    <DIR>          Profile84
    
    0 讨论(0)
  • 2020-12-10 01:24

    There is yet another path that produces this error. Here is how to reproduce it:

    (1) Create a nuget package from a VS project (project 1).
    (2) In project 2 that references project 1, install the project 1 nuget package.
    (3) the installation will fail with the "same key" error.

    The solution is to simply remove the reference to project 1 before installing the nuget package.

    0 讨论(0)
  • 2020-12-10 01:24

    I had the same problem installing Autofac and Autofac MVC 5 Integration. I solved this problem using Manage Nuget Packages in the solution, I unchecked both packages (Uninstall), restarted Visual Studio and reinstalled the package successfully.

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