Ever pull down the source code for a project, only to find many errors of the “The type or namespace name ‘Optimization’ does not exist in the namespace ‘System.Web’ (are you missing an assembly reference?)” variety?
This just happened to me because I pulled down the Page of Photos source code from github for the first time to a certain dev machine. Not all of the binary library dependencies are checked into github (trying to just check in source code), so how does this happen and how should it be fixed?
In my experience, this usually relates to NuGet packages. There are at least two reasonable solutions.
Solution #1: Capture All Binaries (not recommended)
Check into source control the binaries for those packages your project depend on so they’ll always be there. Personally, that seems so last year, and I don’t take this approach for libraries available through NuGet.
(Having private libraries is no longer a reason to do this either. Check out MyGet,org for a hosted private solution that works fine with NuGet machinery.)
Solution #2: Empower NuGet to Self-Heal
Right-click on the Solution from the Visual Studio Solution Explorer and notice the two NuGet-related options in the pop-up menu. To fix the problem at hand in the most convenient manner, simply select “Enable NuGet Package Restore” which is the second of the NuGet-related options.
You will then get an explanation of what’s about to happen:
If you choose “Yes” then NuGet will think for a few seconds before declaring victory:
You might notice there are some new NuGet-related artifacts in your solution.
Now if you again right-click on the Solution from Visual Studio’s Solution Explorer menu, you will notice that the “Enable NuGet Package Restore” menu is gone, leaving only the “Manage NuGet Packages for Solution” option. Select the “Enable NuGet Package Restore” menu to bring up the NuGet management dialog.
Click on “Restore” and your solution should begin to heal itself by downloading the many missing NuGet packages. You can feel the excitement as NuGet thinks it through..
.. and thinks some more ..
.. then – Ta Da! – you suddenly have a bunch of downloaded libraries.
Now your solution will happily compile once more.
Note that this is a one-time & long-term solution since now NuGet is empowered to pull down missing packages whenever needed. (Not “any old packages” of course – just those you’ve added to the projects within the solution.) When you freshly pull down a build (just the source) from source control it helps, of course, but build machines will also enjoy this.