Global Assembly Cache (GAC)

The Global Assembly Cache (GAC) is a machine-wide cache of code. It can be found on every computer where the CLR is installed. The GAC is a storehouse of public/shared assemblies and allows applications to share assemblies instead of having the assembly distributed with each application.

Assemblies must be strong named before being installed in the GAC. The GAC performs integrity checks on all files that make up the assembly (at the time of its installation) to ensure that the assembly has not been tampered with.

Note: Unless explicitly required, do not share an assembly. Keep assembly dependencies private, and locate assemblies in the application directory.

Mention the demerits of installation of an assembly in the GAC

The application can no longer be replicated or installed by using the xcopy command (used to copy the application directory), if one of the assemblies that make up an application is placed in the GAC. The assembly must be moved in the GAC as well.

Mention the benefits of installation of an assembly in the GAC
  • Shared Location – An assembly which has to be used by multiple applications should be placed in the GAC. Add a version policy statement to the Machine.config file which will redirect references to the assembly.
  • File Security – Since it is installed in the systemroot directory, the GAC GAC inherits the Access Control List (ACL). So, only Administrators should be allowed to delete files from the GAC.
  • Side-by-side versioning – The GAC can maintain multiple copies of assemblies with the same name but different version information.
  • Additional search location – Before using the codebase information in the configuration file, the CLR runtime checks the GAC for the requested assembly.

Mention the ways to deploy an assembly into the GAC
  • Use an installer designed to work with the GAC for installing assemblies.
  • Use Gacutil.exe (Global Assembly Cache tool (gacutil.exe) is a developer tool provided by the Windows Software Development Kit (SDK)) to deploy an assembly into the GAC.
    Gacutil.exe does not provide assembly reference counting and other features provided by the Windows Installer. So it should only be used in development environment.

Where is the GAC located?

.NET Framework 4 & above – The default location for GAC is %windir%\Microsoft.NET\assembly
Versions earlier to .NET Framework 4 – The default location for GAC is %windir%\assembly

No comments:

Post a Comment