This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

.NET Framework
.NET 1.1+

Adding Assemblies to the Global Assembly Cache

The global assembly cache (GAC) provides a centralised, machine-wide storage location for .NET assemblies. When you add an assembly to the GAC, you allow it to be shared by many programs, rather than requiring a copy to be installed for each application.

Installing Using the GAC Utility

The Global Assembly Cache Utility is a command line tool that should be executed from the Visual Studio command prompt. The utility provides various functions, including allowing an assembly to be installed into the GAC and uninstalled at a later time. To install an assembly to the GAC, use the -i switch and provide the name of the DLL file, including the path if the file is not in the current folder. For example, to install an assembly named "MyAssembly" held in a file named "MyAssembly.dll", you would execute the following command:

gacutil -i MyAssembly.dll

After you install your assembly, you can view it by browsing to the assembly folder. To remove an assembly that is no longer required, use the -u switch. When uninstalling, the name of the assembly, not the DLL, must be provided. For example:

gacutil -u MyAssembly

Copying Assemblies into the GAC

A second manner in which to install an assembly into the GAC is using Windows Explorer. In this case, the DLL file can simply be copied into the assembly folder. To uninstall the assembly, select it and delete it from the folder.

Referencing a GAC Assembly in Visual Studio

Even when your assembly will be held in the GAC, you must still provide a reference to it during development. You can add the reference in the same way that you would any other. However, once included in your project, you should select the reference in the Solution Explorer and set its "Copy Local" property to false. This will prevent the DLL file from being copied to the output folder when you compile your software.

When you copy your compiled software folder to the target machine, the version of the shared assembly in the GAC will be used automatically. If the required assembly is not correctly registered in the GAC, you will receive a run-time error when it is accessed. This error indicates that the CLR, "Could not load file or assembly". If you see this error, ensure that your assembly is correctly installed.

30 November 2008