2
votes

I am trying to package my project file and creating a nuget package using something like this: NuGet pack file.csproj -p Configuration=$(ConfigurationName); -NoPackageAnalysis.

But the problem is it's putting the files/folders relevant to project in "content" folder and assemblies in "lib" folder but I want files/folder in root and library in bin folder something like this .enter image description here But right now my folder structure is this : enter image description here

The structure of my nuspec file is

<?xml version="1.0"?>
<package >
    <metadata>
        <id>$id$</id>
        <version>$version$</version>
        <title>$title$</title>
        <authors>abc</authors>
        <owners>abc</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>abc</description>
        <releaseNotes></releaseNotes>
        <copyright>Copyright 9999</copyright>
        <tags></tags>
    </metadata>
    <files>
        <file src="bin\**" target="bin" />
        <file src="$target$\**\*.*" target=""/>
    </files>  
</package>

Even excluding from my nuspec file results in the same output structure shown in second image. I am using nuget version 4.1.0 and I also tried with earlier version of nuget like 2.8.6.

2

2 Answers

2
votes

I struggled with this as well, but it is important to understand the difference between the <files /> collection in /package and the <contentFiles /> collection in /package/metadata.

The <files /> collection tells the packager which files to put in your package, in the lib, content or tools directory of your package.

Note: you don't need to use this collection, you can also use a convention-based working directory.

The <contentFiles /> collection tells the package consumer how to use the files contained in the package.

In your case the .nuspec file should look something like this (not really sure about the $target$ part though:

<?xml version="1.0"?>
<package >
    <metadata>
        <id>$id$</id>
        <version>$version$</version>
        <title>$title$</title>
        <authors>abc</authors>
        <owners>abc</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>abc</description>
        <releaseNotes></releaseNotes>
        <copyright>Copyright 9999</copyright>
        <tags></tags>
        <contentFiles>
            <files include="bin/**" buildAction="None" copyToOutput="true" />
        </contentFiles>
    </metadata>
    <files>
        <file src="bin\**" target="content\bin" />
        <file src="$target$\**\*.*" target="content"/>
    </files>  
</package>
0
votes

I had similar problem where I had to put a file in the package root(because an installed add-in app would always look there for the file).

I wanted my.dll to be available inside the packages/My.App.101 folder. So I did this :

<?xml version="1.0"?>
<package >
    <metadata>
        <id>My.App</id>
        <version>101</version>
        <title>title</title>
        <authors>abc</authors>
        <owners>abc</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>abc</description>
        <releaseNotes></releaseNotes>
        <copyright></copyright>
        <tags></tags>
    </metadata>
    <files>
        <file src="My.App.dll" target="/" />
    </files>  
</package>

target="/"

And so this should work for you

<files>
    <file src="YourFolder\yourfile.extension" target="bin/" />
    <file src="YourFolder\yourfile.extension" target="bin/anotherfolder/" />
</files> 

target="bin/"

Happy Packaging :)