Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding all files of a type in NuGet

Problem: I have .sql files in my Visual Studio project which I want to exclude from my NuGet package. These .sql files are nested into various directories, and I have been unable to successfully exclude all .sql files from my nuget package.


1: I've created a .nuspec file by running the following command on my target project:

nuget spec

2: I've edited the resulting nuspec file so that it looks like this:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>Security Core Impl</description>
    <releaseNotes>Security Core Impl</releaseNotes>
    <copyright>Copyright 2013</copyright>
    <tags>Security Core</tags>
  </metadata>
  <files>
    <file src="**\*.dll" target="lib\net40\" exclude="**\*.sql;" />
  </files>
</package>

3: I run the following command to build my .nupkg:

nuget pack -Prop Configuration=Release

Whenever I install this package into another project, however, the .sql files get included. I've tried a few different variations of the exclude above, and have tried the -Exclude switch. Nothing seems to work.

All .sql files are marked:

  • Build Action: None
  • Copy to Output Directory: Do not copy

I have also tried clearing my NuGet cache via Visual Studio options.

Note: The NuGet package is hosted on a private server.

like image 596
Dylan McCurry Avatar asked Mar 12 '13 00:03

Dylan McCurry


2 Answers

I've just been having the exact same issue, but with .txt files. The solution as pointed out by a colleague is to change the Build Action from "Content" to "None".

like image 106
Antony Scott Avatar answered Oct 03 '22 08:10

Antony Scott


I'm assuming your *.sql files are under the content folder of the package?

<file src="**\*.dll" target="lib\net40\" exclude="**\*.sql;" /> tells NuGet to add all .DLL files under lib\net40. SQL files are ignored as your include didn't include them anyway.

Can you try adding <file target="content\" exclude="**\*.sql;" /> to the nuspec?

like image 28
maartenba Avatar answered Oct 03 '22 10:10

maartenba