visual-studionugetnuget-packagenuget-spec

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


Solution

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