2
votes

I have a .nuspec file that goes like the one below. In the files section, I'm trying to copy the .nuspec file itself, so when the package is installed, it winds up in a "Components/tst" directory in the target project (so the dependencies information contained in the .nuspec is available in the target project):

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    ...
  </metadata>
  <files>
    <file src=".\tst.nuspec" target="content\Components\tst\tst.nuspec" />

    <file src="Component\script.js" target="content\Components\tst\script.js" />
    <file src="Component\style.less" target="content\Components\tst\style.less" />
  </files>
</package>

The problem is that when I create the .nupkg file (using nuget pack), the tst.nuspec file is not copied to the content\Components\tst\tst.dependencies file inside the package. And when I install the package, the tst.nuspec file is not copied to the target project.

The other files in the files section (script.js and style.less) are copied fine.

Is there any way I can persuade nuget pack to copy the .nuspec file itself, along with the other files? If not, what would be the best way to copy the .nuspec file to the target project?

1

1 Answers

1
votes

Looking at the NuGet source code this is not supported when using NuGet.exe pack Your.nuspec. All .nuspec files are filtered out when packaging.

    internal void ExcludeFiles(ICollection<IPackageFile> packageFiles)
    {
        // Always exclude the nuspec file
        // Review: This exclusion should be done by the package builder because it knows which file would collide with the auto-generated
        // manifest file.
        var wildCards = _excludes.Concat(new[] { @"**\*" + Constants.ManifestExtension });

So you can either modify NuGet's source code or add the .nuspec file after NuGet has generated the .nupkg file, which is a zip file, manually or programatically.