Specifying which .nuspec file to use when packing a project

Feb 2, 2012 at 11:48 PM

It would be useful to be able to specify which .nuspec to use when packing a project, so that if you want to have more than one nuspec file for a project, you could.  For example, you could do something like this:

nuget pack MyProject.csproj -Spec MySpec1.nuspec

nuget pack MyProject.csproj -Spec MySpec2.nuspec

Right now, "pack" only works with a single .nuspec that matches the name of the project.

Feb 3, 2012 at 5:23 AM

Why do you have more than one?

Feb 3, 2012 at 6:34 AM

Its totally meaningless to use multiple



bing a bingo, bingo bingo!!!!

web directory

Feb 3, 2012 at 6:58 PM
Edited Feb 3, 2012 at 7:09 PM

A couple of scenarios, when you want to generate more than one package from the same project:

  1. You have a lot of content files (images, etc.), and want to make two separate packages, one for all the content, and one for the library.  You don't want to deal with deleting and re-adding hundreds of the same content files every time you need to release a bug fix that's only involves a change to the dll.  Depending on which version control system you're using, that can take ages.
  2. You have configuration transforms files and want to make two separate packages, one for initial installation and setup, and one for the library (which will get updated more often).  If this was in one package, when you update with a bug fix contained in the dll, it's going to try to remove all the config settings, then re-add them which keeps (unnecessarily) re-ordering your config elements (assuming the values are unchanged), or sometimes duplicates entries, depending on the structure of your xml.

(These aren't hypotheticals, btw; they're things I've run into a lot.)

In both of these cases, you want the information to still be dynamically read from the project (AssemblyInfo, dependencies, new files to include, etc.).  You could sometimes accomplish these things through one spec and really elaborate use of the -Exclude flag with the pack command, but it's unweildy and hard to maintain.

Since the spec is supposed to be a companion to the project, when you need to make more than one package from a project, it would make sense to be able to accomplish that through multiple .nuspec files, rather than making really long, complicated command line statements.

Feb 3, 2012 at 7:54 PM

In fact, judging from the comments in this work item, it sounds as if at some point early on, there was some sort of support for this (emphasis mine):

  • "Verified that if only one .nuspec file exists on the folder, it is used to create the package."
  • "Verified that nupack.exe does not recursively look for nuspec files"
  • "Verified that passing the nuspec parameter works when there are multiple files."

So they're talking about rules for how to handle packing in a directory when there's more than one nuspec.  I think this was before they added support for packing directly from a project file, but you can see that having multiple specs was something they were dealing with.