installing nuget package “same key has already bee

2019-01-19 09:58发布

i am trying to install Microsoft.Bcl.Build 1.0.14

nuget returns

Installing 'Microsoft.Bcl.Build 1.0.14'. Successfully installed 'Microsoft.Bcl.Build 1.0.14'. Adding 'Microsoft.Bcl.Build 1.0.14' to LeadTracker.Calendar. Uninstalling 'Microsoft.Bcl.Build 1.0.14'. Successfully uninstalled 'Microsoft.Bcl.Build 1.0.14'. Install failed. Rolling back... An item with the same key has already been added.

This also happens with json.net and other packages.

I can add nancy and topshelf but not json.net and bcl.

I have tried it in VS2012 and 2013. I have also tried uninstalling nuget and reinstalling. I have also tried adding the nuget to an empty class library and an empty console app. The same error is always returned.

This also happens with json.net and other packages.

I have also tried with no packages file

Any ideas most appreciated.

Here is the command and stacktrace

PM> Install-Package Microsoft.Bcl.Build Installing 'Microsoft.Bcl.Build 1.0.14'. You are downloading Microsoft.Bcl.Build from Microsoft, the license agreement to which is available at http://go.microsoft.com/fwlink/?LinkId=329770. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device. Successfully installed 'Microsoft.Bcl.Build 1.0.14'. Adding 'Microsoft.Bcl.Build 1.0.14' to GoogleCalendarIntegration. Uninstalling 'Microsoft.Bcl.Build 1.0.14'. Successfully uninstalled 'Microsoft.Bcl.Build 1.0.14'. Install failed. Rolling back... Install-Package : An item with the same key has already been added. At line:1 char:1
+ Install-Package Microsoft.Bcl.Build
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], ArgumentException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPac     kageCommand   PM> $error[0].exception.stacktrace    at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)  at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)    at System.Collections.ObjectModel.KeyedCollection`2.AddKey(TKey key, TItem item)    at System.Collections.ObjectModel.KeyedCollection`2.InsertItem(Int32 index, TItem item)    at System.Collections.ObjectModel.Collection`1.Add(T item)    at NuGet.CollectionExtensions.AddRange[T](ICollection`1 collection, IEnumerable`1 items)    at NuGet.NetPortableProfileTable.BuildPortableProfileCollection()    at NuGet.NetPortableProfileTable.get_Profiles()    at NuGet.NetPortableProfileTable.GetProfile(String profileName)    at NuGet.NetPortableProfile.Parse(String profileValue, Boolean treatOptionalFrameworksAsSuppor tedFrameworks)    at NuGet.VersionUtility.IsPortableLibraryCompatible(FrameworkName projectFrameworkName, Framew orkName packageTargetFrameworkName)    at NuGet.VersionUtility.IsCompatible(FrameworkName projectFrameworkName, FrameworkName package TargetFrameworkName)    at NuGet.VersionUtility.<>c__DisplayClass8`1.<TryGetCompatibleItems>b__15(IGrouping`2 g)    at System.Linq.Enumerable.WhereListIterator`1.MoveNext()    at System.Linq.Buffer`1..ctor(IEnumerable`1 source)    at System.Linq.OrderedEnumerable`1.<GetEnumerator>d__0.MoveNext()    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)   at NuGet.VersionUtility.TryGetCompatibleItems[T](FrameworkName projectFramework, IEnumerable`1  items, IEnumerable`1& compatibleItems)    at NuGet.ProjectSystemExtensions.GetCompatibleItemsCore[T](IProjectSystem projectSystem, IEnum erable`1 items)    at NuGet.ProjectManager.ExtractPackageFilesToProject(IPackage package)    at NuGet.ProjectManager.AddPackageReferenceToProject(IPackage package) at NuGet.ProjectManager.Execute(PackageOperation operation)    at NuGet.ProjectManager.Execute(IPackage package, IPackageOperationResolver resolver)    at NuGet.ProjectManager.AddPackageReference(IPackage package, Boolean ignoreDependencies, Bool ean allowPrereleaseVersions)    at NuGet.VisualStudio.VsPackageManager.<>c__DisplayClass83.<AddPackageReference>b__85() at NuGet.VisualStudio.VsPackageManager.RunProjectAction(IProjectManager projectManager, Action  action)    at NuGet.VisualStudio.VsPackageManager.AddPackageReference(IProjectManager projectManager, IPa ckage package, Boolean ignoreDependencies, Boolean allowPrereleaseVersions)    at NuGet.VisualStudio.VsPackageManager.<>c__DisplayClass3.<InstallPackage>b__7() at NuGet.VisualStudio.VsPackageManager.RunSolutionAction(Action action)    at NuGet.VisualStudio.VsPackageManager.InstallPackage(IProjectManager projectManager, String p ackageId, SemanticVersion version, Boolean ignoreDependencies, Boolean allowPrereleaseVersions, B oolean skipAssemblyReferences, ILogger logger)    at NuGet.VisualStudio.VsPackageManager.InstallPackage(IProjectManager projectManager, String p ackageId, SemanticVersion version, Boolean ignoreDependencies, Boolean allowPrereleaseVersions, I Logger logger)  at NuGet.PowerShell.Commands.InstallPackageCommand.InstallPackage(IVsPackageManager packageMan ager)    at NuGet.PowerShell.Commands.InstallPackageCommand.ProcessRecordCore()    at NuGet.PowerShell.Commands.NuGetBaseCommand.ProcessRecord() PM>

10条回答
太酷不给撩
2楼-- · 2019-01-19 10: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.

查看更多
Deceive 欺骗
3楼-- · 2019-01-19 10:26

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.

查看更多
别忘想泡老子
4楼-- · 2019-01-19 10:28

Go into your packages directory and delete all version of the package you don't need anymore.

Then try installing the correct version. I think it is looking at all the folders in that directory and trying to add them to some kind of dictionary/hashset and finding two.

查看更多
ゆ 、 Hurt°
5楼-- · 2019-01-19 10:31

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.

查看更多
地球回转人心会变
6楼-- · 2019-01-19 10:34

This happens in the .Net Core and .Net Standard Portable Class Library space a lot. Even though I have not traced the true root of the problem it seems to happen most when I directly modify the project.json dependencies section with packages that have a lot of other external dependencies (that have terms associated with them).

If you can identify the library responsible and remove all the dependencies and use the proper nuget package management tool to add the packages. It has not uncommon to have to delete and recreate the CLI completely!

查看更多
Rolldiameter
7楼-- · 2019-01-19 10:37

Check your packages.config Inside there, check for the packages you are trying to install. Maybe some reference are already there and this avoid that you can install the new ones.

If you find there the references, delete the reference from the packages.config and try to install again the package.

It happened to me sometimes that inside packages.config are some old reference that still left there even after removing the package from the Nuget Package Manager.

If not, you can delete the entire packages.config, then if you have the option to let Nuget download the packages, when you build your solution, the packages will be downloaded again.

I hope this helps

查看更多
登录 后发表回答