Nuspec file element limitations

Jul 1, 2011 at 12:05 AM

I'm building a sample NuGet package for my library, and wish to include the source code for several sample C# projects in the content/ directory. However, doing something like this is non-ideal:

<file src="..\..\src\Samples\**" target="content\Samples\" />

Unfortunately, while this pulls in all the relevant source code, it also pulls in the obj/ directories.

For this reason, would it be possible to add either a) an 'exclude' wildcard attribute to the <file> element, b) allow regex expressions in the 'src' attribute, c) both?

Thanks very much.

Jul 1, 2011 at 12:31 AM
Why not copy the items you want over to another directory and include that one instead?
Jul 1, 2011 at 12:37 AM

No doubt, that's a possibility, but it then requires a pre-build script. It's all time- and space-consuming. Having directory exclusion built into NuGet.exe itself would be ideal, for sure.

Jul 1, 2011 at 12:38 AM

I noticed there is an -Exclude option for the `pack' command. Perhaps this could be extended to exclude directories? In any case, it would seem to make more sense to have this exclude option as a part of NuSpec; indeed even in the <file> element.

Jul 1, 2011 at 12:47 AM
Use the exclude like this:

nuget pack -exclude ..\..\src\Samples\obj\**

and it works.

the option to have it in the nuspec file is nice. I don't think this is the first time this has been requested though....
Jul 1, 2011 at 1:11 AM

You should be able to Exclude directories today by simply excluding all files under it. For instance if your folder structure is

    └─── Code.cs
        └─── Obj.dll
        └─── Obj.pdb

nuget.exe pack -Exclude Src\Samples\obj\*
nuget.exe pack -Exclude **\obj\*

should do the job.

Jul 1, 2011 at 2:38 AM

Thanks for the quick replies.

pranavkm: That almost worked! I changed it slightly to `-Exclude **\obj\**` and it did the job, so thanks.

ferventcoder: Yeah, I'm sure that would have done the job too; just happened to try pranavkm's first. Anyway, if this suggestion has been made a few times (and you seem to agree it would be useful), is there any chance of it appearing in the next release? :-) I would even take the time to submit the patch myself to get this working, but unfortunately I'm experiencing some weird build errors (namely a Target Invocation error and I'm also missing FxCop).


Jul 5, 2011 at 5:42 PM

So, any more thoughts on this guys? :-)

Jul 5, 2011 at 5:51 PM
File an issue. Be specific in the issue about what you want. It will be triaged.

If you want to get a quick response on it, get a lot of people to vote it up.

(sorry this was not clear from our conversation)
"Be passionate in all you do"