Wednesday, July 07, 2004

Referring Global assembly from Add Reference dialog box

The typical way of adding references to .NET Components is to use the .NET Tab on the Add Reference…. Dialogue in your project.

VS.NET builds the complete list of available .NET Components by looking in certain directories. By default it looks in the install directory of the .NET Framework (%SystemRoot%\Microsoft.NET\Framework\vSomethingNumber). It will also look in any directory listed with in a certain registry key (see below).

When you are using a nonstandard GAC component, you might want Visual Studio .NET to list it in the Add Reference... dialog under the .NET tab, without having to browse for it.

Simply installing your assembly to the Global Assembly Cache (GAC) would not help in this scenario. The Add Reference dialog box is path based and does not enumerate the components from GAC.

Here is how to install, reference, and use a nonstandard GAC Component:
Create a directory where your nonstandard GAC components will be stored.
ex. “C:\WINDOWS\Microsoft.NET\Framework\[FolderName]
Add a registry key like the one below pointing to where the assembly resides.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework

\AssemblyFolders\[FolderName]
@="C:\\WINDOWS\\Microsoft.NET\\Framework\\[FolderName]"
Copy your Strongly Named component to this directory.
Install the component in the GAC (ex. gacutil /i MyComponent.dll)
The GAC’d component will now be available to add as a project reference in the Add Reference… .NET Tab.
NOTE: Since you are referencing a GAC’d component, the Copy Local property will be set to ‘False’. Leave it AS IS. The component will be available in the server GAC when you deploy to the shared environment and should NOT be copied as part of the project.