Tuesday, November 29, 2005 - Posts

Visual Studio 2005: Erronous MSDN documentation, Add Reference and the GAC

When I read this document on MSDN I got a little scared. The document claims that assemblies installed in the GAC will automatically be listed in the Add References dialog in Visual Studio 2005. Fortunately the documentation is wrong about this; assemblies in the GAC aren’t listed in Visual Studio. Why is this fortunate? To list an assembly in the Visual Studio IDE you’ll have to know what you’re doing. Developers like to learn things using a trial and error approach, and installing an assembly in the GAC might be something a developer would try since the assemblies listed in the Add Reference dialog are “shared”. I made this assumption way back in the Visual Studio .NET days. At the time I was ignorant about CAS, simply because I hadn’t had the time to learn about it, and didn’t know if there was a difference between GAC’ed and “regular” assemblies. If a GAC’ed assembly had appeared within the Visual Studio IDE, I’d probably keep installing assemblies into the GAC unnecessarily until I eventually learned more about the GAC and CAS. In .NET 2.0 assemblies installed in the GAC run with full thrust, this makes sense because you need administrative privileges to install an assembly in the GAC. Installing assemblies to the GAC just to have them appear in the Add References dialog could easily lead to gaping security holes in software.

So now that you know why adding an assembly to the GAC doesn’t add it to the Add References dialog, I’ll let you know how to add assemblies to that dialog. You’ve got several options.

  1. Add a new key under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx. If you want an installation only for the current user add the key to HKEY_CURRENT_USER instead. The value of the key should be the folder path that you want Visual Studio to look in for assemblies to include in the Add References dialog. This registry path is specific to VS 2005 and the .NET Framework 2.0 and will not work for previous versions of VS or the .NET Framework.
  2. Add a new key under HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders. The value of the key should be the folder path that you want Visual Studio to look in for assemblies to include in the Add References dialog. This registry path is global and any folders listed here will be processed by VS .NET 2002, VS .NET 2003 and VS 2005 as well as the .NET Framework 1.0, 1.1 and 2.0. Keep backward compability in mind when choosing this option.
  3. Place a copy of your assembly in the Common7\IDE\PublicAssemblies folder beneath your Visual Studio 2005 installation folder (Typically c:\Program Files\Microsoft Visual Studio 8\). This is not a recommended approach; choose either option 1 or 2 if you can.

A dark day for patterns

John Vlissides, who was one of the authors of the legendary Gang of Four book, died from cancer this weekend. John's book is probably one of the most important books ever written on software architecture, and he has not only influenced many other technical writers, he has influenced the way we develop software today.
Rest in peace John, and many thanks for your contribution to the software architecture community.