7

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?

4

2 回答 2

7

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.

于 2012-12-07T07:44:40.483 回答
3

I had this error trying to use the package visualizer and it ended up that my packages.config had the same package name in it more than once with different versions.

于 2015-05-03T14:16:38.617 回答