Custom nuspec file as default

Jul 31, 2011 at 9:04 AM
Edited Jul 31, 2011 at 12:18 PM


When I create a nuspec file from assembly with the below code,


..\Nuget.exe spec -AssemblyPath .\lib\net40-full\myassebly.dll


it creates the following node and subnode


      <dependency id="SampleDependency" version="1.0" />


I do not want that.

I created a folder called @Nuget for my company's packages and my nuget.exe is sitting inside this folder and also my packages that I am creating and updating. 

That would be great to put a base file for nuspec file inside this folder and see it as a default .nuspec. then when I create the package from a dll file, it overrides the field that it can be (version no, description, etc.)

is it possible to do that now?

Jul 31, 2011 at 10:56 AM

I am currently achieving this with following powershell code but I suppose it is not the best way of doing that;

..\nuget.exe spec
$nuspecContentFirst = (Get-Content .\Package.nuspec)[0..12]
$nuspecContentLast = (Get-Content .\Package.nuspec)[-1..-2] | Sort-Object
Set-Content .\Package.nuspec $nuspecContentFirst
Add-Content .\Package.nuspec $nuspecContentLast
ii .\Package.nuspec

Aug 1, 2011 at 2:17 PM

Note that if you create a nuspec from a csproj instead of an assembly, it will have the correct dependencies instead of the SampleDependency. But if you want the nuspec to have your own custom settings, you'll need to do your own transforms. But if your projects have correct metadata, there should be no need to do that.

Aug 2, 2011 at 9:17 PM

What triggers the <dependencies> to be added in the .nuspec file when I create the .nuspec file from my .csproj file? I have created a .nuspec file in the same folder that holds the .csproj file, but no dependencies have shown up. What in the .csproj file triggers the inclusion of dependencies?

Aug 2, 2011 at 9:36 PM

@eric: actually, what happens is that the dependencies don't go in the nuspec at all. But then when you run 'nuget pack' on the csproj, the dependecies end up in the package. The idea is to avoid repeating the dependencies that are intrinsic in the project in the nuspec file (hence staying DRY). This post has info on the full workflow.

Aug 2, 2011 at 10:03 PM


This is what you were referring to in the other post. The nuget spec command when executed in the same folder as the .csproj file does not put the <dependencies> section in the .nuspec file, but will add the other assemblies that the project is dependent upon in the lib folder. Correct?

Aug 2, 2011 at 10:07 PM

Well, not exactly. There are two different things:

  1. If the project has nuget package references, they become package references of the new package you're building
  2. If the project has assembly/project references that are not nuget packages, then those assemblies end up in the lib folder
Aug 3, 2011 at 3:05 PM


You said:

    "If the project has nuget package references, they become package references of the new package you're building".

The way I interpret this statement is that If I have added nuget packages to the project that I am running nuget spec against, then these assemblies will show up as dependencies in the package that I create from my .csproj file.  Is this correct?  If so, then I'm not seeing the references/dependencies showing up.


Aug 3, 2011 at 5:46 PM

To be perfectly correct, it's the packages that show up as dependencies, not the assemblies (a package can contain 0 or more assemblies).

Not sure why it didn't work for you. Please try following the steps in my post exactly, as it shows this working from beginning to end. That may help understand what you are doing differently.

Aug 3, 2011 at 6:34 PM

It is working properly for me now. Thank you for all of your help in clarifying the process for me.


Aug 3, 2011 at 6:38 PM

Could you explain what you were doing differently when it didn't work, in case someone else runs into this later and finds this thread?

Aug 3, 2011 at 7:18 PM

The issue with not have the package assembly showing up in the package that I created from the corresponding .csproj file was that I have installed the query 1.6.2 package which does not have any assemblies, hence none showed. up. This issue was pilot error.  when I installed the elmah package and repackaged my package, elmah showed up as a dependency.  The nusepc file create never showed a dependency section as you noted earlier, but it did show up as a dependency in the package. :-)

Aug 3, 2011 at 8:22 PM

Ah ok, makes sense, thanks!