Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An item with the same key has already been added nuget error

I am currently creating a nuget package with a nuspec file but getting the following error:

An item with the same key has already been added.

My command I am using is:

nuget pack "MyProject.csproj" -o "..\Packages"

This is my nuspec file:

    <?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <id>$id$</id>
        <version>$version$</version>
        <title>$title$</title>
        <authors>$author$</authors>
        <owners>$author$</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>$description$</description>
        <language>$language$</language>
    </metadata>
    <files>
        <file src="bin\MyLibrary*.dll" target="lib\net45" />
    </files>
</package>

The nuspec file I am using is also used when packaging other packages withing the same library. Could this be the reason why the above error is occurring? Any ideas?

like image 865
amateur Avatar asked Dec 07 '12 00:12

amateur


People also ask

How do I fix NuGet recovery failed?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

How do I clean and restore a NuGet package?

After you enable package restore in Options, you can right-click the solution in Solution Explorer and select Restore NuGet Packages to restore packages anytime. If you enabled automatic restore in Options, Package Restore happens automatically when you create a project from a template or build a project.

How do I reference an existing NuGet package from a new project?

NET Core project. After you install a NuGet package, you can then make a reference to it in your code with the using <namespace> statement, where <namespace> is the name of package you're using.


1 Answers

It might be that you are adding files in nuspec that are also getting added when you call pack on the .csproj (files/dlls referenced by the csproj). If so you can remove the file references from the nuspec file and give it a try. how does your nuspec file look like?

I created it with the following steps
1. create the Mylibrary project
2. let me add a dependency, I installed ninject package to the project
3. build
4. nuget spec mylibrary.csproj
5. nuspec file generated, I didn't add any file or dependency manually to the file
6. nuget pack mylibrary.csproj
7. nuget pack would automatically add ninject as a dependency and also add mylibrary.dll into the correct folder
8. http://npe.codeplex.com/ is a nice tool to open the nupkg file and see what got generated inside the package.

like image 155
Deepak Avatar answered Sep 17 '22 23:09

Deepak