Enable Package Restore and Projects loaded in other Solutions

Apr 19, 2012 at 3:13 AM
Edited Apr 19, 2012 at 3:15 AM

When using the new Enable Package Restore feature (MVC4 beta) in Visual Studio to apply to a Solution that contains projects that are also used in other solutions, it breaks those projects for other solutions that do not have Enable Package Restore enabled.

To see this break:
Create a Solution (A) and add a couple of new projects - I use Class LIbrary and Web Project of any kind but it doesn't really matter what types of projects. Create another solution (B) and add the same Class Library from Solution (A) to this new solution. Compile both solutions to ensure they work.

Now Enabled Package Restore in Solution A. Compile. All is well.

Switch to Solution B - project will ask to reload due to changes. But reload fails calling out missing build target for Nuget Package Restore. Same behavior if loading Solution anew: Loading project will not load the project and explict load causes error unless Package Restore is enabled.

Why this is a problem
I think this is a deal breaker for using this feature because if you distribute your projects to others to use and integrate into their own solutions it's almost guaranteed that the project import will fail. It'll fail until Package Restore is enabled.

In fact, I'm now in a place where I have third party solutions that I'm working on that require Package Restore and I added projects of my own to it. When I add my projects, they are automatically upgraded to use package restore. If I now go back to my old solution that solution now won't load my project unless i enable package restore. And so it goes: Basically this feature is forcing me to push all projects into package restore. If it was only for me that'd be OK but it's when projects move to other machines developers that this becomes a royal pain. You end up with this cascading effect of projects breaking for you, then for others like a virus.

There's gotta be a better way
Seems to me there has got to be a better way to make this work. Rather than forcing the project files to hold the build targets, couldn't solution manage this instead? If it was at the solution level it's a single file that's affected  and doesn't break the lower level components end up getting reused in other solutions.

+++ Rick ---

Apr 19, 2012 at 5:42 PM

For one, the solution file does not have easy ways to introduce optional pre-build tasks which makes this difficult. Secondly, you would be taking away the flexibility of building individual project files if we tie package restore to the solution.

Apr 20, 2012 at 8:29 PM

I thought that 1.7 fixed this issue. It doesn't add the targets to the project until you add references to nuget packages. A project that doesn't use NuGet package restore can be shared between solutions.

Apr 20, 2012 at 10:12 PM

That helps a little bit, but these days just about every project has NuGet references...