December 10th, 2005, 05:40 AM
.NET Framework General: What is the global assembly cache?
Q: What is the global assembly cache?
Each computer on which the common language runtime is installed has a machine-wide code cache called the 'Global Assembly Cache'. The global assembly cache (or GAC as it is commonly known) stores assemblies specifically designated to be shared by several applications on the computer. The global assembly cache is located in 'Windows/WinNT' directory and inherits the directory's access control list that administrators have used to protect the folder.
Assemblies installed in GAC should adhere to a specific versioning scheme that will allow them for side-by-side execution (multiple versions of the same assembly can be maintained in the GAC) of different code versions.
Shared Assemblies including all the important .NET System assemblies implementing the Framework Class Library reside within GAC. The GAC was originally called Fusion Cache and is implemented using Fusion.dll in .NET Framework.
Assemblies placed in the GAC must have the same assembly name and file name (not including the file name extension). For example, an assembly with the assembly name of 'myAssembly' must have a file name of either 'myAssembly.exe' or 'myAssembly.dll'.
- Scenarios for installing Assemblies in GAC
There are multiple reasons why an assembly should be installed in GAC:
- File Security:
Administrators usually protect the 'Windows/WinNT' directory using an access control list (ACL) to control access. Because the GAC is located in 'Windows/WinNT' folder, this means that the GAC folder inherits the access rights from the 'Windows/WinNT' folder, and only administrators can modify the contents of the GAC. This will ensure that assemblies that are installed in GAC are not being accidentally removed/modified by in-experienced users.
- Shared Location:
GAC acts as a common place for installing assemblies that are shared by multiple applications on the same machine. A common misconception is that in order to make the .NET assemblies available to COM InterOp or to the unmanaged code, the assemblies should be installed in GAC. However, this does not mandate installing assemblies in the GAC. Only those assemblies that are shared with other applications on the same machine should be installed in GAC.
- Side-by-Side versioning:
Side-by-side execution means having the ability to install and use multiple versions of the same assembly. In simple words side-by-side versioning means having the same assembly present with multiple versions but with the same name. GAC can contain multiple copies of the same assembly with different versions, which allows a robust support for versioning in the Common Language Runtime.
- As an additional search location:
When an assembly needs to be loaded by the Common Language Runtime, the CLR first checks the GAC for the assembly.
- Pre-Requisites for installing an assembly in GAC
To install an assembly in GAC, the assembly must be signed with a strong name.
In order to help assemblies to sign with a string name, one can use the Strong Name Tool. Further information can also be found in the following article.
Originally Posted by .NET Framework Documentation
- Installing/uninstalling an assembly in GAC
There are multiple ways of installing an assembly in GAC:
- Using Windows Installer:
This is a preferred way for installing shared assemblies and should be the only way to install the shared assemblies on production systems (or non-development machines).
- Global Assembly Cache Tool:
The Global Assembly Cache Utility Tool can be used to install or uninstall assemblies in GAC. It also allows us to view or manipulate the contents of the GAC. The common syntax of 'GACUTIL.exe' is:
To install a strong named assembly from the command prompt in the GAC use:
gacutil [options] [assemblyName | assemblyPath | assemblyListFile]
To uninstall a strong named assembly from the command prompt in the GAC use:
gacutil /i myAssembly.dll
To view the contents of the GAC we can use:
gacutil /u myAssembly.dll
To check if an assembly ('myAssembly.dll') is already present in the GAC:
gacutil /l myAssembly.dll
- Other ways:
There are other ways also to install/uninstall the assemblies to/from GAC and to view the contents. Following links will give some insight on these tools:
Last edited by Andreas Masur; December 11th, 2005 at 05:34 AM.
Click Here to Expand Forum to Full Width
This is a Codeguru.com survey!