NuGet 2.0 Solution Level Package Restore from MSBuild

Topics: General
Jul 13, 2012 at 10:49 AM

I'm using the .nuget folder the v2 RTM release spits out.

When I Install-Package xunit.runners, the .nuget dir gains a packages.config.

When I do a an msbuild of a .sln file, no restore of solution level packages occurs.

Right now, as a workaround I'm doing a:

    .nuget\nuget.exe install .nuget/packages.config -o packages

before MSBuilding the solution as I have [an equivalent to] a post build step that has a reliance on the tool per project so something needs to guarantee the precondition of the package being restored.

Is there a way I can/should trigger that? Should the standard targets be doing anything to assist? If not, what is the purpose of the file / who consumes it otherwise? Is it just the update notification process when one manages packages at the solution level?

Developer
Jul 13, 2012 at 4:09 PM

You are using it in the way it is intended. You could call the restore package target on the NuGet.targets file by passing in the right parameters, but at this point, we haven't quite refactored it enough to work outside of a project. But that said, 

a) It's to be used by your build system to trigger restores

b) It lets us keep track of solution level packages (since they don't appear in individual projects)

Jul 13, 2012 at 8:35 PM

Thanks for the clear response. I'll give that a try. I'm racking my brains to remember but IIRC I ended up with an irreconcilable issue due to the child project baking a Property-based dependency on inclusion too early. Will report back.

As it happens I came up with a cleaner short term approach in my context which was to move my nuget invocation into the .targets file at the .csproj level which was going to consume it, which saves me an 'out of band' dependency of needing a 'pre build set of solutions in a folder'.proj to run before any solution in that folder needs to be run.

Is there any chance of something happening which will cause either the msbuilding of a .sln or a precondition check when the nuget.targets are included in a .csproj ending up guaranteeing this has happened any time soonish? It seems like the sort of thing you wouldnt want to be forcing on people that don't speaka da xml build langs?

Aug 14, 2012 at 6:49 PM

There really needs to be a way to have solution level dependencies. Today, it is not possible to consume a NuGet dependency from a MSBuild Script if the dependency is a MSBuild Task.  I'm not sure the best way around this... For example, you might want to use the MSBuildTasks NuGet Package which requires you to import the targets file... The targets file would only exist after the package has been downloaded and installed via NuGet.