从csproj打包时,NuGet包含tools文件夹

时间:2016-11-23 16:33:20

标签: nuget nuget-package

我正在尝试从csproj文件创建一个nuget包。该软件包将在tools文件夹中包含install.ps1脚本,在内容文件夹中包含一些文件。

但是,似乎从csproj文件打包时,nuget将从相应的nuspec文件中提取包信息(描述,标签等),但不包含任何其他内容。它忽略与nuspec文件和内容文件夹位于同一目录中的tools文件夹。

以这种方式打包时,nuget似乎也忽略了nuspec文件的contentFiles部分中包含的文件。

这是预期的行为吗?如果是,有没有办法让我从csproj打包并将内容和工具文件夹包含在包中?

我意识到我只能使用 一个nuspec文件,这可行,但我有多个软件包,我正在尝试以这种方式构建并手动管理依赖项变得不那么简单。

运行NuGet 3.4.4.1321

我的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>
    <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 个答案:

答案 0 :(得分:0)

原来这个文件让我感到困惑。内容文件不是文件的替代品。在NuGet 3中,两者都可以同时使用。

使用我的nuspec文件中Files标记之外的metadata标记,我可以指定进入工具和内容文件夹的项目。

更新了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>

希望这有助于万一其他人被这里的文档绊倒。

可以在这个NuGet Issue中找到更多的讨论。

答案 1 :(得分:0)

你可以nuget pack -Tool

  

工具 - 指定项目的输出文件应放在工具文件夹中。

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