2

我有一个 .nuspec 文件,如下所示。在文件部分,我试图复制 .nuspec 文件本身,所以当安装包时,它会在目标项目的“组件/tst”目录中结束(因此 .nuspec 中包含的依赖项信息是在目标项目中可用):

<?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>

问题是当我创建 .nupkg 文件(使用 nuget pack)时,tst.nuspec 文件没有复制到包内的 content\Components\tst\tst.dependencies 文件中。而且当我安装包时, tst.nuspec 文件不会复制到目标项目中。

文件部分中的其他文件(script.js 和 style.less)被很好地复制。

有什么办法可以说服 nuget pack 复制 .​​nuspec 文件本身以及其他文件?如果没有,将 .nuspec 文件复制到目标项目的最佳方法是什么?

4

1 回答 1

1

查看 NuGet 源代码,使用NuGet.exe pack Your.nuspec. 打包时会过滤掉所有 .nuspec 文件。

    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 });

因此,您既可以修改 NuGet 的源代码,也可以在 NuGet 生成 .nupkg 文件(这是一个 zip 文件)后手动或以编程方式添加 .nuspec 文件。

于 2014-07-26T16:52:00.557 回答