Troopers
Troopers

Reputation: 5452

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

Upvotes: 3

Views: 2604

Answers (2)

Leo Liu
Leo Liu

Reputation: 76670

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.

Upvotes: 2

Troopers
Troopers

Reputation: 5452

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>

Upvotes: 2

Related Questions