NuGet restore and project imports

Mar 1, 2012 at 3:45 AM

I see that this was already commented on by jmcgar at, but wondering if there are any suggestions on how to deal with it.

I have a package that needs to add some additional MSBuild steps to perform code generation. I've got a reasonable handle on how add the import to my custom targets during package install to the project file. However, I also want to be able to take advantage of the new Restore functionality so I don't have to check my package files into source control.

The restore functionality is implemented through an another MSBuild extension, and does a good job of restoring the packages before build begins. However, the <Import> for custom targets will happen when the project file is loaded. At this point on a machine that has not yet updated the packages, the import will point to a file that won't exist until a build is started.

This is a nasty circular dependency that I don't see a good solution to.

My current thinking is to abandon having a central .targets file, and to just push all of my properties and targets directly into the project file at install time, but this seems a bit messy (and more difficult to be able to fully undo when uninstall happens).

I'm hoping that I'm overlooking something simple. Any thoughts?

Mar 1, 2012 at 6:17 AM

Solution level packages like msbuild targets play very poorly with package restore in 1.6. In 1.7, we're making it slightly better by tracking these packages i na packages.config file at the solution root. However, since solution files don't provide a clean mechanism to specify target files, the only way to restore these packages would be an explicit step in your build process that runs nuget.exe install on this file to restore packages.