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.
Pingback: Reading Notes 2013-09-09 | Matricis
Pingback: Are you missing an assembly reference? Why, yes I am. So kind of you to ask. | TechCentral
Thanks for finallʏ talking about >Are you missing an assembly reference?
Why, yes І am. So kind of you to asҝ. | Coding Out Loud <Loved it!
Thanks – I had tried this a few times with a project template that I had downloaded. Restore would appear to complete but references still showed up with warning triangles.
Examining the references path showed that it was looking in “..\packages\…….” which didn’t match my structure. This is because I had created the new project with the checkbox ‘Create subfolder for solution name’ cleared. I started again with this box ticked, restored the missing nuget packages, and all appears to be working now.
i like your title! I followed your directions, but when I came to the Manage NuGet Packages for Solution window, mine did not let me “restore”. (your directions said : 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….. and yet I did not have “Enable NuGet Package Restore” menu, but only the “Manage NuGet Packages for Solution” option which I did select to get to the next window that did not give me the Restore button.) I did get a nuget.org link under online and I am working to find the libraries I need to restore. Is there an easier way to get them all restored? I branched code in TFS from another developer and have no knowledge of what libraries could be needed. i am also new to working with web applications. any advice is welcome. Thanks!
Yes, I ran into this issue, as well (the selecting a missing menu option issue). I am using VS 2010 and was able to then go to “Manage NuGet Packages for Solution” and go to “Updates”. This then enabled me to force NuGet to Update each of the dependencies and solved the majority of my errors related to “Missing… etc.”
> Now if you again right-click on the Solution from Visual Studio’s Solution Explorer menu, you will notice that the [A] “Enable NuGet Package Restore” menu is gone,
leaving only the [B] “Manage NuGet Packages for Solution” option.
Select the [A] “Enable NuGet Package Restore” menu to bring up the NuGet management dialog.
Could you walk me through once more how I select the option that is gone?
Visual Smarter has a lot widgets helping manage references including copying, removing, changing properties automatically, and other tweaking. Hope you find them helpful.
http://visualsmarter.blogspot.com/2015/12/solution-widgets-in-visual-smarter.html
http://visualsmarter.blogspot.com/2015/04/visual-studio-reference-concerns-and.html