Usually I either work on existing solutions or create new ones from scratch. It's very rare that I'll be given an existing project to work on that I have not worked on before.
This has just happened. I have been seconded to help out a struggling team on their large product which is old, and has continually evolved ever since. It has tens of projects within the solution, each with many shared references and loads of nuget packages (probably around 50 in the main project and handfuls in the referenced projects).
Easy - Restore Packages Please!
I thought, this will be easy, I'll just right click the solution and choose restore packages.
The linked article above says:
To promote a cleaner development environment and to reduce repository size, NuGet Package Restore installs all a project's dependencies as listed in either the project file or packages.config. Visual Studio can restore packages automatically when a project is built.
I've added some highlights for what I reckon are the important bits. So I do a restore, and it pulls down all the packages into the packages folder. Good. I rebuild solution. mmmm, 25,000 errors according to Resharper. Not good.
I know that it has not reinstalled the packages because:
- Some need license agreements.
- It would take a while to install, and Visual Studio was not busy.
- There was no output in the nuget output window.
Be Wary of the Update All
Firstly, I tried to add packages via nuget - this was a disaster. The solution was old, so the packages it would install were clearly the wrong versions and often completely incompatible with the version it should've had.
What a mess. I got a new copy of the solution and started again.
Stackoverflow to the rescue, mostly
This answer on Stackoverflow gave some good ideas, namely;
Update-Package -reinstall This worked really well. It went off for an hour to install packages. Make sure you watch the output window because it asks questions which need answers. You could be therefore a while if it is waiting for your input!
References still broken
Even after the packages had installed, I still had missing references and 6,000 errors.
I bet the missing references are so old they were added before nuget had been invented!
I had to find the version numbers of the DLLs that were missing, by checking the versions in the BIN directory of an existing deployment.
I was then able to get those old versions via Nuget, and choose the correct version by using the dropdown list. Once I did this for the broken references, the solution would finally compile.
I'm still installing references now, even after writing this blog post. If you find yourself having to restore loads of references, make sure you have plenty of time!