【问题标题】:How to exclude all content files?如何排除所有内容文件?
【发布时间】:2018-12-11 21:43:13
【问题描述】:

使用 NuGet 4.6.2,如何在使用 PackageReference 从项目文件创建包时排除所有内容文件?

我将此命令作为 postbuid 事件运行:

$(SolutionDir)\.nuget\nuget pack $(ProjectPath) -IncludeReferencedProjects -properties Configuration=$(ConfigurationName) -symbols

我试过这个 nuspec 文件:

<package>
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <releaseNotes></releaseNotes>
    <copyright>$copyright$</copyright>
    <tags></tags>
    <contentFiles>
      <files include="**\*.*" exclude="**\*.*" />
    </contentFiles>
  </metadata>
  <files>
    <file src="**\*.*" target="content" exclude="**\*.*" />
  </files>
</package>

但内容文件始终在包中

【问题讨论】:

    标签: visual-studio nuget nuget-package nuget-spec


    【解决方案1】:

    只需对files使用一个空节点

    <package>
      <metadata>
        <id>$id$</id>
        <version>$version$</version>
        <title>$title$</title>
        <authors>$author$</authors>
        <owners>$author$</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>$description$</description>
        <releaseNotes></releaseNotes>
        <copyright>$copyright$</copyright>
        <tags></tags>
      </metadata>
      <files />
    </package>
    

    【讨论】:

      【解决方案2】:

      如何排除所有内容文件?

      .nupsec中使用空文件节点确实是一种有效的方法。

      作为替代方案,您可以将额外的元数据添加到现有的&lt;Content&gt; 项目到您的项目文件中,以使用如下条目覆盖:

      <ItemGroup>
        <Content Include="Test.txt">
          <Pack>false</Pack>
        </Content>
      </ItemGroup>
      

      有关更多详细信息,请参阅pack scenarios

      希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-01-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-04-20
        • 2021-06-28
        • 2015-06-03
        相关资源
        最近更新 更多