我正在尝试安装Microsoft.Bcl.Build 1.0.14
nuget返回
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.
json.net和其他软件包也会发生这种情况。
我可以添加nancy和topshelf,但不能添加json.net和bcl。
我在VS2012和2013中尝试过它。我也尝试卸载nuget并重新安装。我也尝试将nuget添加到空类库和空控制台应用程序中。始终返回相同的错误。
json.net和其他软件包也会发生这种情况。
我也试过没有包文件
任何想法最受赞赏。
这是命令和堆栈跟踪
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>
答案 0 :(得分:16)
检查packages.config
里面的内容,检查您要安装的软件包。也许已经有一些参考,这避免了你可以安装新的。
如果您找到引用,请从packages.config中删除引用并尝试再次安装该包。
有时我发生在packages.config中是一些旧的引用,即使从Nuget包管理器中删除包后仍然留在那里。
如果没有,您可以删除整个packages.config,然后如果您可以选择让Nuget下载软件包,那么在构建解决方案时,将再次下载软件包。
我希望这会有所帮助
答案 1 :(得分:11)
您的堆栈跟踪告诉该故事,它是NuGet.NetPortableProfileTable.BuildPortableProfileCollection()
失败。简而言之,它迭代了一组PCL参考装配配置文件,并且不止一次地遇到相同的配置文件。这是一个非常强烈的提示,表明c:\program files (x86)\reference assemblies\microsoft\framework\.netportable
目录的内容已损坏。
有许多方法可以解决这个问题:
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
答案 2 :(得分:4)
看起来NuGet正在您的计算机上找到重复的可移植类库(PCL)配置文件。遗憾的是,密钥未记录在异常调用堆栈中,这会使事情变得简单。
您可以尝试Jon Skeet的PclPal程序,该程序可以列出PCL配置文件并查看是否有任何重复。
我有另一个MonoPcl program做类似的事情。它指的是Mono,但适用于Windows。它使用NuGet源代码,因此它会遇到与您在Visual Studio中看到的问题相同的问题。但是,您应该能够modify the code捕获异常或进行一些额外的日志记录,以查看导致问题的重复PCL配置文件的内容。
答案 3 :(得分:3)
进入packages
目录并删除不再需要的所有版本的软件包。
然后尝试安装正确的版本。我认为它正在查看该目录中的所有文件夹,并尝试将它们添加到某种字典/ hashset并找到两个。
答案 4 :(得分:3)
只需更新工具中的Nuget包管理器 - 扩展和更新 - 更新 - 视觉工作室库 - 更新Nuget包管理器
答案 5 :(得分:2)
还有另一条路径会产生此错误。复制方法如下:
(1)从VS项目(项目1)创建nuget包。
(2)在引用项目1的项目2中,安装项目1 nuget程序包。
(3)安装将失败,并显示“相同密钥”错误。
解决方案是在安装nuget软件包之前简单地删除对项目1的引用。
答案 6 :(得分:1)
我刚刚遇到了同样的问题,但安装NuGet Package Manager的最新更新解决了这个问题。
答案 7 :(得分:0)
我在安装Autofac和Autofac MVC 5集成时遇到了同样的问题。 我使用解决方案中的Manage Nuget Packages解决了这个问题,我取消选中了两个软件包(卸载),重新启动了Visual Studio并成功重新安装了软件包。
答案 8 :(得分:0)
在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)
发现bin \ Debug文件夹中存在多个Nuget .spec文件。
答案 9 :(得分:0)
这在.Net Core和.Net标准可移植类库空间中发生了很多。即使我没有追溯到问题的真正根源,但是当我直接修改project.json依赖项部分时,它似乎最常发生在包含许多其他外部依赖项(具有与之关联的术语)的包中。
如果您可以识别负责的库并删除所有依赖项并使用适当的nuget包管理工具来添加包。必须完全删除并重新创建CLI,这并不罕见!
答案 10 :(得分:0)
我有类似的问题。当我使用记事本删除项目的.csproj文件中具有指定包的重复PackageReference元素时,此问题已得到纠正。
答案 11 :(得分:0)
就我而言,我从程序包管理器控制台中运行了一个dotnet restore
以获取重复的密钥
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]