nuget pack xxx.csproj adds dependency on code-only package

Dec 8, 2011 at 12:28 PM

I have a project I want to package, which references a few packages himself.
One of the package is a code-only package, like netfx-guard (

I've generated the nuspec using nuget spec project.csproj.
When I want to pack it using nuget pack project.csproj, it takes all the dependencies from the packages.config and merge it in the nuspec.

As one of the dependencies is code-only, I don't want it listed in the dependencies of my package.
I haven't found a way to either exclude code-only package nor exclude it in the nuspec (only inclusion is possible)
For now, I've made my nuspec by hand with <files> and <dependencies> but I would like to take advantages of the csproj packing functionality.

What do you think is best ?
Ability to exclude a package in the nuspec, even when the package is present in the packages.config of the project ?
Or consider a package without lib folder to be a code-only package and exclude it automatically ? 

Dec 8, 2011 at 6:11 PM

Why don't you wanted it listed?

Dec 9, 2011 at 9:26 AM

I have this hierarchy of packages :

  • package Helper, code-only, netfx-like package. Doesn't contains anything but a Content folder with C# source code
  • package Startup, a normal package which will provide an assembly
  • package Startup use package Helper

Package Startup use helpers from the Helper package, so I want it listed in the packages.config of the Startup project.
However, as this helpers are used internally in the Startup package and aren't necessary to use the Startup library I don't want it to be marked as a dependency in Startup's package.
A dependency in the nupkg to the Helper package will install it in every project using the Startup package, but as it isn't needed to run it, all my projects will have an unnecessary source code file.

In order to remove this automatic dependency, I couldn't use the nuget pack xxx.csproj format and needed to list all my dependencies by hand in my .nuspec file.

I don't think my needs are those of everyone and an automatic exclusion of all code-only packages might be problematic to others.
That's why I wanted to have the possibility to exclude some of the dependencies listed in the packages.config.

Dec 9, 2011 at 7:10 PM

I do agree that there are cases where dealing with source packages (or mixed dll/sources packages) can be tricky and we're not always handling it well. The mixed case is actually trickier, because you can't just exclude it since the binaries are needed at runtime.


  • Package A brings in a.cs and a.dll
  • Package B uses Package A, which means that
    • a.cs will be part of the sources of b.dll
    • a.dll will be needed at runtime
  • Now consider a package C that depends on B:
    • Both a.dll and b.dll should be present at runtime
    • BUT c.dll may not want a.cs in its sources. Yet this is what will happen
Dec 10, 2011 at 4:03 AM

Another example is Paul Stovell's, which uses the NuGet package format for packaging deployments. It explicitly does not support package dependencies. Take the example of a database deployment package. It contains:

 - Deploy.ps1
 - tools\Deploy.exe
 - tools\dbup.dll (this is a dependency, but I have included as a <file> in the NuSpec.
 - tools\scripts\Script0001.sql etc

Currently I cannot exclude the packages from packages.config, maybe simply an -ExplicitDependencies switch to opt out of this functionality?