4
votes

I'm trying to create a nuget package from a csproj file. This package will include an install.ps1 script in the tools folder and some files in the content folder.

However, it seems like when packing from a csproj file, nuget will pull the package information (description, tags, etc.) from the corresponding nuspec file, but not anything else. It ignores the tools folder that is in the same directory as the nuspec file as well as the content folder.

When packing this way nuget also seems to ignore files included in the contentFiles section of the nuspec file.

Is this expected behavior? If it is, is there a way for me to pack from a csproj and get the content and tools folders to be included in the package?

I realize I could just use only a nuspec file and this would work, but I have multiple packages I'm trying to build this way and managing the dependencies manually becomes a less than trivial task.

Running NuGet 3.4.4.1321

My nuspec file:

<?xml version="1.0"?>
<package>
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$id$</title>
    <authors>authors</authors>
    <owners>$owners$</owners>
    <projectUrl>http://dummy.url</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>the description</description>
    <copyright>$copyright$</copyright>
    <releaseNotes>$releaseNotes$</releaseNotes>
    <contentFiles>
        <files include="content\App.config.install.xdt"/>
        <files include="content\App.config.uninstall.xdt"/>
        <files include="temp\App.config"/>
    </contentFiles>
    <tags>wpf testing</tags>
  </metadata>
</package>
2
Can you post your nuspec file please?Andy Lamb

2 Answers

1
votes

Turns out the documentation for this confused me a bit. Content Files are not a replacement for Files. In NuGet 3, both can be used simultaneously.

Using the Files tag outside of the metadata tag in my nuspec file allowed me to specify items that go into the tools and content folder.

Updated nuspec:

<?xml version="1.0"?>
<package>
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$id$</title>
    <authors>authors</authors>
    <owners>$owners$</owners>
    <projectUrl>http://dummy.url</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>the description</description>
    <copyright>$copyright$</copyright>
    <releaseNotes>$releaseNotes$</releaseNotes>
    <tags>wpf testing</tags>
  </metadata>
 <files>
    <file src="App.config.install.xdt" target="content"/>
    <file src="App.config.uninstall.xdt" target="content"/>
    <file src="tools\install.ps1" target="tools"/>
  </files>
</package>

Hopefully this helps in case anyone else gets tripped up by the docs here.

A bit more discussion can be found in this NuGet Issue.

0
votes

You could do nuget pack -Tool

Tool - Specifies that the output files of the project should be placed in the tool folder.

https://docs.microsoft.com/en-us/nuget/tools/cli-ref-pack