web-dev-qa-db-ja.com

nugetパッケージのインストール「同じキーは既に追加されています。」

microsoft.Bcl.Build 1.0.14をインストールしようとしています

ヌジェが返します

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>
27
Jules

スタックトレースは物語を伝え、失敗するのはNuGet.NetPortableProfileTable.BuildPortableProfileCollection()です。簡単に言うと、PCL参照アセンブリプロファイルのセットを反復処理し、同じプロファイルに複数回遭遇します。これは、c:\program files (x86)\reference assemblies\Microsoft\framework\.netportableディレクトリのコンテンツが破損しているという非常に強力なヒントです。

損傷を修正する方法はたくさんあります。

  • ファイルのコピーなど、このディレクトリをいじくり回していることを積極的に覚えている場合は、行った操作を取り消してください。
  • これを回避する最も安全な方法は、Visual Studioバージョン> = VS2010をアンインストールすることですall。次に、手動でディレクトリをクリーンアップし、まだ存在する浮遊ファイルを削除します。その後、VSを再インストールします。
  • 安全ではないが、より高速な方法は、renamec:\ program files(x86)\ referenceアセンブリディレクトリにインストールし、 マルチターゲティングパック 。成功を約束することはできません。
  • 重複を自分で見つけて削除することができます。ディレクトリ構造は次のようになります。

 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
13
Hans Passant

packages.config内部で、インストールしようとしているパッケージを確認します。すでにいくつかの参照が存在している可能性があり、これにより新しいものをインストールできるようになります。

参照が見つかった場合は、packages.configから参照を削除し、パッケージを再度インストールしてください。

Packages.configの内部には、Nuget Package Managerからパッケージを削除した後も残っている古い参照が残っていることがあります。

そうでない場合は、packages.config全体を削除し、Nugetにパッケージをダウンロードさせるオプションがあれば、ソリューションをビルドするときにパッケージが再度ダウンロードされます。

これが役立つことを願っています

16
Oscar Bralo

NuGetがマシン上で重複したポータブルクラスライブラリ(PCL)プロファイルを検出しているようです。キーが例外コールスタックに記録されないのは残念です。

Jon Skeetの PclPal プログラムを試してみてください。このプログラムは、PCLプロファイルをリストし、重複するものがないかどうかを確認できます。

別の MonoPclプログラム がありますが、これは同様のことを行います。 Monoを指しますが、Windowsで動作します。 NuGetソースコードを使用するため、Visual Studioで見られるのと同じ問題が発生します。ただし、例外をキャッチするために コードを変更する を実行するか、問題を引き起こしている重複PCLプロファイルが何であるかを確認するために追加のログを記録する必要があります。

5
Matt Ward

このエラーを生成する別のパスがあります。再現方法は次のとおりです。

(1)VSプロジェクト(プロジェクト1)からnugetパッケージを作成します。
(2)プロジェクト1を参照するプロジェクト2で、プロジェクト1のnugetパッケージをインストールします。
(3)インストールは「同じキー」エラーで失敗します。

解決策は、nugetパッケージをインストールする前に、プロジェクト1への参照を単に削除することです。

3
AQuirky

ちょうどpdateツールのNugetパッケージマネージャー-拡張機能と更新プログラム-更新--visual studioギャラリー--update Nugetパッケージマネージャー

3

packagesディレクトリに移動し、不要になったパッケージのすべてのバージョンを削除します。

次に、正しいバージョンをインストールしてください。私はそれがそのディレクトリ内のすべてのフォルダを見て、それらをある種の辞書/ハッシュセットに追加し、2つを見つけようとしていると思います。

3
Simon_Weaver

私はまったく同じ問題を抱えていましたが、NuGetパッケージマネージャーの最新の更新プログラムをインストールすると問題が解決しました。

2
KasperT

AutofacとAutofac MVC 5 Integrationのインストールで同じ問題が発生しました。ソリューションでManage Nuget Packagesを使用してこの問題を解決し、両方のパッケージのチェックを外して(アンインストール)、Visual Studioを再起動し、パッケージを正常に再インストールしました。

1
rpou0830

Building 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)

複数のNuget .specファイルがbin\Debugフォルダーに存在することがわかりました。

0
user3048212

これは、.Net Coreおよび.Net Standard Portable Class Libraryスペースで頻繁に発生します。問題の本当の原因を突き止めていませんが、他の多くの外部依存関係(関連する用語を持つ)を持つパッケージでproject.jsonの依存関係セクションを直接変更すると、ほとんど発生するようです。

責任のあるライブラリを特定し、すべての依存関係を削除し、適切なnugetパッケージ管理ツールを使用してパッケージを追加できる場合。 CLIを完全に削除して再作成する必要があることは珍しくありません!

0

同様の問題がありました。メモ帳を使用して、プロジェクトの.csprojファイルで指定されたパッケージを持つ重複したPackageReference要素を削除すると修正されました。

0
elamaunt