Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude all content files?

With NuGet 4.6.2, how to exclude all content files when creating the package from a project file using PackageReference?

I run this command as postbuid event :

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

I tried this nuspec file :

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

But content files are always in the package

like image 780
Troopers Avatar asked Oct 23 '25 14:10

Troopers


2 Answers

Simply use an empty node for 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>
like image 121
Troopers Avatar answered Oct 26 '25 10:10

Troopers


How to exclude all content files?

Using an empty files node in .nupsec is really an effective method.

As an alternative, you could add extra metadata to the existing <Content> item to your project file to override with entries like the following:

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

See pack scenarios for some more details.

Hope this helps.

like image 42
Leo Liu-MSFT Avatar answered Oct 26 '25 09:10

Leo Liu-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!