Global Assembly Cache
From Wikipedia, the free encyclopedia
The Global Assembly Cache or GAC is a machine-wide .NET assemblies cache for Microsoft's CLR platform. The approach of having a specially controlled central repository, addresses the shared library concept while helping to avoid pitfalls of other solutions that lead to drawbacks like DLL hell.
Contents |
[edit] Reasons for Usage
There are several reasons to install an assembly into the GAC:
[edit] Shared Location
Assemblies that should be used by all applications can be put in the global assembly cache. For example, if all applications should use an assembly located in the global assembly cache, a version policy statement can be added to the Machine.config file that redirects references to the assembly.
[edit] File Security
Administrators often protect the Windows directory using an Access Control List (ACL) to control write and execute access. Because the global assembly cache resides in the Windows directory, it inherits that directory's ACL. It is recommended that only users with Administrator privileges be allowed to delete files from the global assembly cache.
[edit] Side-by-Side Versioning
Multiple copies of assemblies with the same name but different version information can be maintained in the global assembly cache.
[edit] Additional Search Location
The CLR checks the GAC for an assembly that matches the assembly request before probing or using the codebase information in the configuration file.
[edit] Requirements
Assemblies residing in the GAC must adhere to a specific versioning scheme which allows for side-by-side execution of different code versions. Specifically, such assemblies must be "strongly named".
[edit] Usage
gacutil.exe is the .NET utility used to work with the GAC.
One can check the availability of a shared assembly in GAC by using the command: gacutil.exe /l <assemblyName>
One can register a shared assembly in the GAC by using the command: gacutil.exe /i <assemblyName>
[edit] Example of Usage
A computer has two .NET assemblies both named AssemblyA, but one is version 1.0 and the other is version 2.0. Since it is required that both be compiled to a file named AssemblyA, they cannot exist in the same directory within the FAT32 filesystem. Instead, the virtual file system of the GAC can be used by applications that need to use each version of the assembly specifically.
[edit] Implementation
The GAC as a construct does not actually exist within the Windows OS. It is implemented and managed by the .NET Framework. The folder within %systemroot% named assembly contains all globally-available assemblies with mangled filenames so that the version and public key tokens can be included. Each version can therefore exist within the same location and be called without requiring subsequent versions to preserve code entry point locations as usual. Explorer allows the drag-and-drop installation of assemblies into this folder only if they would otherwise be permitted to be installed from the command line.
A calling application may specify specific versions of an assembly when referencing them, so the CLR can simply refer to the filename to use the correct one.