2014-06-26 9 views
20

Sto cercando di installare Microsoft.Bcl.Build 1.0.14installazione del pacchetto nuget "la stessa chiave è già stata aggiunta."

NuGet torna

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. 

Questo succede anche con json.net e altri pacchetti.

Posso aggiungere nancy e topshelf ma non json.net e bcl.

L'ho provato in VS2012 e 2013. Ho anche provato a disinstallare Nuget e reinstallare. Ho anche provato ad aggiungere il nuget a una libreria di classi vuota ea un'app di console vuota. Lo stesso errore viene sempre restituito.

Ciò accade anche con json.net e altri pacchetti.

Ho provato anche con il file senza pacchetti

Tutte le idee più apprezzate.

Ecco il comando e 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> 
+0

Hai provato a rimuovere la voce nel file package.config? – christof13

+0

sì e provato senza un file di pacchetti. Ho aggiornato la domanda. – Jules

+1

Provare a installare il pacchetto NuGet dalla finestra della console di Gestione pacchetti. Quindi dovresti essere in grado di visualizzare l'intero stack di chiamate dell'errore se si esegue "$ error [0] .exception.stacktrace" dopo l'installazione non riesce. Questo potrebbe darci un indizio migliore sul perché e dove sta fallendo. –

risposta

10

Il tuo stack-trace racconta la storia, è NuGet.NetPortableProfileTable.BuildPortableProfileCollection() che fallisce. In poche parole, itera l'insieme dei profili dell'assieme di riferimento PCL e incontra lo stesso profilo più di una volta. Questo è un suggerimento molto forte che il contenuto della tua directory c:\program files (x86)\reference assemblies\microsoft\framework\.netportable è corrotto.

Ci sono molti modi possibili per andare su di fissare il danno:

  • Se si dispone di un raccoglimento attiva di armeggiare con questa directory, come la copia dei file, quindi annullare quello che hai fatto.
  • Il modo più sicuro per procedere è disinstallare tutte le versioni di Visual Studio> = VS2010. Quindi ripulisci a mano la directory, cancellando tutti i file vaganti che sono ancora presenti. Quindi reinstallare di nuovo VS.
  • Il modo non-sicuro, ma più rapido è quello di rinominare la directory c: \ program files (x86) \ reference assembly e installare multi-targeting pack. Non posso promettere il successo.
  • Puoi provare a trovare il duplicato e rimuoverlo.La struttura di directory simile a questo:

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 
4

Sembra NuGet è trovare un profilo duplicato Portable Class Library (PCL) sulla vostra macchina. È vergognoso che la chiave non sia registrata nell'eccezionalità del callstack, il che renderebbe le cose facili.

Si potrebbe provare il programma PclPal di Jon Skeet che può elencare i profili PCL e vedere se c'è qualcosa di duplicato.

Ho un altro MonoPcl program che fa una cosa simile. Si riferisce a Mono ma funziona su Windows. Utilizza il codice sorgente di NuGet in modo che abbia lo stesso problema riscontrato in Visual Studio. Tuttavia, dovresti essere in grado di rilevare l'eccezione modify the code o inserire alcune registrazioni aggiuntive per vedere qual è il problema del profilo PCL duplicato.

+0

Grazie, il tuo programma MonoPcl mi ha aiutato !! – AstralisSomnium

16

Controlla la tua packages.config Al suo interno, controllare per i pacchetti che si sta tentando di installare. Forse alcuni riferimenti sono già lì e questo evita che tu possa installare quelli nuovi.

Se si trovano i riferimenti, eliminare il riferimento da packages.config e provare ad installare nuovamente il pacchetto.

A volte capita che all'interno di packages.config ci sia qualche vecchio riferimento che rimane ancora lì anche dopo aver rimosso il pacchetto dal Gestore pacchetti Nuget.

In caso contrario, è possibile eliminare l'intero packages.config, quindi se si ha l'opzione di consentire a Nuget di scaricare i pacchetti, quando si crea la soluzione, i pacchetti verranno nuovamente scaricati.

Spero che questo aiuta

+1

phew. così felice che questo ha risolto il mio problema e non ho dovuto ricorrere a tutto il divertimento che tutta la gente ha a che fare con la risposta di @Hans! – GraehamF

+0

+1 Questo può facilmente accadere se si modifica manualmente un 'packages.config' - NuGet rifiuterà di lavorare con un progetto che ha voci duplicate per lo stesso assembly. – StuartLC

+0

Sì, avevo 2 pacchetti nel pacchetto.config con lo stesso id, ma con numeri di versioni differenti. Quindi ho mantenuto l'ultima versione e rimosso la versione precedente, quindi ha funzionato. – arame3333

3

Vai nella directory packages ed eliminare tutti versione del pacchetto non è necessario più.

Quindi provare a installare la versione corretta. Penso che stia guardando tutte le cartelle in quella directory e provando ad aggiungerle a qualche tipo di dizionario/hashset e a trovarne due.

0

Ho avuto lo stesso problema con l'integrazione di Autofac e Autofac MVC 5. Ho risolto questo problema utilizzando Gestisci pacchetti Nuget nella soluzione, ho deselezionato entrambi i pacchetti (Disinstalla), riavviato Visual Studio e reinstallato il pacchetto con successo.

0

Ho appena avuto esattamente lo stesso problema, ma l'installazione dell'ultimo aggiornamento per NuGet Package Manager ha risolto il problema.

3

Proprio aggiornamento il gestore dei pacchetti Nuget in Strumenti - estensione e aggiornamenti - aggiornamenti --visual Studio Gallery --update Nuget gestore di pacchetti

+0

Grazie per la tua semplice risposta! – Jahan

+0

Questo ha funzionato anche per me. Ho disinstallato nuget (perché non c'era un aggiornamento) e lo ho reinstallato. Questa è stata l'unica cosa che ha funzionato per me. –

0

stavo affrontando lo stesso problema mentre Costruire un progetto 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) 

Trovato che più file Nuget .spec erano presenti nella cartella bin \ Debug.

0

Questo accade nello spazio della libreria di classi standard .Net Core e .Net standard. Anche se non ho tracciato la vera radice del problema, sembra che succeda di più quando modifico direttamente la sezione delle dipendenze project.json con pacchetti che hanno molte altre dipendenze esterne (che hanno termini associati a loro).

Se è possibile identificare la libreria responsabile e rimuovere tutte le dipendenze e utilizzare lo strumento di gestione pacchetti nuget appropriato per aggiungere i pacchetti. Non è raro dover cancellare e ricreare completamente la CLI!

Problemi correlati