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
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With