So, I've been toying around with nuget in anticipation of pushing a nuget package to the public feed and available via the nuget package reference/command line tool in VS2010. While the documentation is pretty explicit in most areas, the one area that
I had the most trouble with is that of adding package dependencies.
I assumed that by adding a reference, say StructureMap as in the below snippet, the referenced package would get automatically resolved and imported into the destination project (the project that added the nuget package).
<dependency id="StructureMap" version="126.96.36.199" />
So, I went about creating my nuspec manifest (including adding the dependent packages), running nuget pack, pushing to a local repository, configuring nuget in vs2010 to point to the local repository, and adding the nuget package via vs2010
Package Manager Console (or Add Library Package Reference Dialog Box). Bam, I receive the following error (or something similar):
Unable to resolve dependency 'StructureMap (≥ 188.8.131.52)'.
An error - awesome! I searched for a resolution online and via Twitter; however, after about 40 minutes, I realized that I was on my own to figure it out... BTW, Scott Hanselman has a great post here on
nuget - it didn't solve my issue, but the steps he describes in both consuming and creating packages is the most straightforward post/tutorial that I've found.
The solution is actually quite simple and makes absolute sense after I thought about it for awhile...
I had to add the dependent packages (nupkg) to my local repository (along side the package that I built). Once I did that, the dependent package resolved and imported without any issues - in this case, StructureMap.
Why does this make absolute sense NOW? Well, imagine that you create a package that is dependent upon another self-generated package (bPack.nupkg depends on aPack.nupkg). There would be no way for the nuget package manager to resolve this dependency
(aPack.nupkg), because the package (aPack.nupkg) wouldn't be registered with the nuget package manager (locally and/or the official nuget feed).
That said, it would be nice if nuget could have a hierarchy of dependency resolutions - sort of how *.config files work. E.g. if the dependent package is not if the current repository (in my case, the local repository), search the closest nuget repository,
if not there, search the next, etc... So, in my case, the package resolution for StructureMap from the local repository would fail (because it is not there), but the 'NuGet official package source' repository does contain the StructureMap nupkg
and could resolve the dependent package and import it as expected. I hope that is clear... ;)
Unfortunately, I'm a little hesitant with pushing my nupkg to the official feed. I'm a bit anxious about opening my nupkg for all to use and the possibility of it failing...
Anyway, I hope this saves someone some of the frustration that I experienced. I'm really enjoying the power of nuget...