All about Global Assembly Cache


If an assembly is to be accessed by multiple applications, the assembly must be placed into a well-known directory, and the CLR must know to look in this directory automatically when a reference to the assembly is detected. This well-known location is called the global assembly cache (GAC), which can usually be found in the following directory (assuming that Windows is installed in the C:\Windows directory):

C:\Windows\Assembly

The GAC directory is structured: it contains many subdirectories, and an algorithm is used to generate the names of these subdirectories. You should never manually copy assembly files into the GAC; instead, you should use tools to accomplish this task. These tools know the GAC's internal structure and how to generate the proper subdirectory names.

While developing and testing, the most common tool for installing a strongly named assembly into the GAC is GACUtil.exe. Running this tool without any command-line arguments yields the following usage:

01 Microsoft (R) .NET Global Assembly Cache Utility. Version 4.0.20928.1
02 Copyright (c) Microsoft Corporation. All rights reserved.
03 Usage: Gacutil <command> [ <options> ]
04 Commands:
05 /i <assembly_path> [ /r <...> ] [ /f ]
06 Installs an assembly to the global assembly cache.
07 /il <assembly_path_list_file> [ /r <...> ] [ /f ]
08 Installs one or more assemblies to the global assembly cache.
09 /u <assembly_display_name> [ /r <...> ]
10 Uninstalls an assembly from the global assembly cache.
11 /ul <assembly_display_name_list_file> [ /r <...> ]
12 Uninstalls one or more assemblies from the global assembly cache.
13 /l [ <assembly_name> ]
14 List the global assembly cache filtered by <assembly_name>
15 /lr [ <assembly_name> ]
16 List the global assembly cache with all traced references.
17 /cdl
18 Deletes the contents of the download cache
19 /ldl
20 Lists the contents of the download cache
21 74 Part I CLR Basics
22 /?
23 Displays a detailed help screen
24 Options:
25 /r <reference_scheme> <reference_id> <description>
26 Specifies a traced reference to install (/i, /il) or uninstall (/u, /ul).
27 /f
28 Forces reinstall of an assembly.
29 /nologo
30 Suppresses display of the logo banner
31 /silent

Suppresses display of all output

As you can see, you can invoke GACUtil.exe, specifying the /i switch to install an assembly into the GAC, and you can use GACUtil.exe's /u switch to uninstall an assembly from the GAC. Note that you can't ever place a weakly named assembly into the GAC. If you pass the file name of a weakly named assembly to GACUtil.exe, it displays the following error message: "Failure adding assembly to the cache: Attempt to install an assembly without a strong name."


Similar Articles