In my project, I was using class library. Now I made that class lib as a NuGet package, remove the class lib and when try to install the package this error appears:"An item with the same key has already been added"?
In my case, I saw this error when my packages.config file contained duplicate package ids which isn't allowed.
You can use the PowerShell script below to find all duplicate packages in your solution. It finds all packages.config files recursively and per packages.config file, it checks for duplicate package ids.
$solutionFolder = "C:\MySolution"
$nugetPackageFile = "packages.config"
$files = Get-ChildItem -Path $solutionFolder -Filter $nugetPackageFile -Recurse
foreach ($file in $files)
{
[xml]$xml = Get-Content $file.FullName
$nodes = Select-Xml "/packages/package/@id" $xml
$packageIds = @{}
foreach ($node in $nodes) {
$packageId = $node.Node.'#text'
try
{
$packageIds.Add($packageId, $packageId)
}
Catch [System.ArgumentException]
{
Write-Host "Found duplicate package in " $file.FullName ". Duplicate package: $packageId"
}
}
}
I had the same error and it got fixed after I upgraded NuGet itself. Use the Tools -> 'Extensions and Updates' dialog box to update NuGet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With