Logo
HOWTO: Reference a Visual Studio assembly in the GAC from an add-in

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: February 2007   Microsoft Visual Studio .NET 2003
Updated: October 2012   Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
      Microsoft Visual Studio 2010
      Microsoft Visual Studio 2012

Introduction

Visual Studio uses assemblies that, among others, are in one of these subfolders of C:\Program Files\<Microsoft Visual Studio folder>:

  • \Common7\IDE
  • \Common7\IDE\PublicAssemblies
  • \Common7\IDE\PrivateAssemblies

But some assemblies are installed only in the Global Assembly Cache (GAC). The GAC is a special folder typically located at:

  • .NET Framework 1.0, 1.1, 2.0, 3.0 and 3.5: C:\Windows\Assembly
  • .NET Framework 4.0 and 4.5: C:\Windows\Microsoft.NET\assembly

The GAC stores different versions of shared assemblies used at run-time by .NET applications. The GAC is actually a set of folders, but when you use the Windows Explorer to browse the first of the GACs (C:\Windows\Assembly), a shell extension shows a unified view (assembly name, version, culture, public key token and arquitecture) of all installed assemblies. The othe GAC folder (C:\Windows\Microsoft.NET\assembly) doesn't have such shell extension.

Sometimes your add-in project needs to reference an assembly that is only in the GAC or installing the VSIP / Visual Studio SDK, for example, the Microsoft.VisualStudio.OLE.Interop.dll assembly.

More Information

If you don't want to install the Visual Studio SDK stuff on your computer just to reference an assembly that is only in the GAC, since Visual Studio doesn't allow to add references to an assembly in the GAC (because the GAC is a deployment feature, not a development feature) you can follow this procedure to extract the assembly from the GAC that has the shell extension (C:\Windows\Assembly):

  • Open a MS-DOS command window (click Start, Run... type cmd and press enter)
  • Use the SUBST command to map a drive letter to the GAC folder:

SUBST G: C:\Windows\Assembly

That maps the drive letter G: to the GAC folder. With the SUBST command you bypass the shell extension.

  • Use Windows Explorer to browse the G: folder. You will see the actual folders, with names like GAC, GAC_32, GAC_MSIL and one subfolder for each assembly. Once you locate the assembly DLL that you are looking for, you can copy it outside the GAC, to the \bin folder of your add-in project and add a reference to it. For example, the Microsoft.VisualStudio.OLE.Interop.dll is in the folder G:\GAC\Microsoft.VisualStudio.OLE.Interop\7.1.40304.0__b03f5f7f11d50a3a.
  • When done, you can undo the mapping the using:

    SUBST G: /D

Most Visual Studio assemblies are not redistributable, which means that your setup should not include them. Rather, Visual Studio (which installs those assemblies in the GAC) should be a prerequisite on the target computer.


Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this


Top