Showing posts with label GAC. Show all posts
Showing posts with label GAC. Show all posts

Sunday, September 27, 2009

GAC is Global Assembly Cache

Each computer where the CLR (common language runtime) is installed has a machine-wide code cache called the “Global Assembly Cache”. The global assembly cache stores assemblies specifically designated to be shared by several applications on the computer.

You should share assemblies by installing them into the global assembly cache only when you need to. As a general guideline, keep assembly dependencies private, and locate assemblies in the application directory unless sharing an assembly is explicitly required. In addition, it is not necessary to install assemblies into the global assembly cache to make them accessible to COM interop or unmanaged code.

There are several reasons why you might want to install an assembly into the global assembly cache:
*  Shared location - Assemblies that should be used by applications can be put in the global assembly cache.
E.g. 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.
*  File security - Administrators often protect the SYSTEMROOT directory using an Access Control List (ACL) to control write and execute access. Because the global assembly cache is installed in the SYSTEMROOT 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. 
*  Side-by-side versioning - Multiple copies of assemblies with the same name but different version information can be maintained in the global assembly cache.
*  Additional search location - The common language runtime checks the global assembly cache for an assembly that matches the assembly request before probing or using the codebase information in a configuration file. 

There are several ways to deploy an assembly into the global assembly cache:
*  Use an installer designed to work with the global assembly cache. This is the preferred option for installing assemblies into the global assembly cache.
*  Use a developer tool called the Global Assembly Cache tool (Gacutil.exe), provided by the Windows Software Development Kit (SDK).
*  Use Windows Explorer to drag assemblies into the cache. 

Assemblies deployed in the global assembly cache must have a strong name. When an assembly is added to the global assembly cache, integrity checks are performed on all files that make up the assembly. The cache performs these integrity checks to ensure that an assembly has not been tampered with, e.g. when a file has changed but the manifest does not reflect the change.

To view a list of the assemblies in the global assembly cache, type the following command at the command prompt - gacutil -l