Understanding and Managing Assemblies in the .NET Framework
The Global Assembly Cache (GAC) is a repository used by the .NET Framework to store assemblies that are shared by multiple applications. It allows for versioning and makes assemblies accessible to any application that needs them, preventing naming conflicts and improving system stability by isolating application dependencies.
When you install an assembly into the GAC, it becomes available to all applications on the machine that are configured to use that specific version of the assembly. This is particularly useful for libraries and components that are intended to be used by many applications, such as runtime libraries provided by Microsoft or third-party shared components.
gacutil.exe.
The primary tool for interacting with the GAC is the Global Assembly Cache Tool (gacutil.exe). This tool allows you to install, uninstall, and list assemblies in the GAC.
gacutil.exe
gacutil.exe is typically located in the .NET Framework SDK directory. You will need to run it from a command prompt with administrator privileges.
gacutil.exe Commands:gacutil /i <assembly_path>
Example:
gacutil /i "C:\MyProject\bin\Debug\MySharedLibrary.dll"
gacutil /u <assembly_name>
The assembly name should include the version, culture, and public key token (e.g., MySharedLibrary,Version=1.0.0.0,Culture=neutral,PublicKeyToken=your_public_key_token).
Example:
gacutil /u MySharedLibrary,Version=1.0.0.0,Culture=neutral,PublicKeyToken=a1b2c3d4e5f67890
gacutil /l
gacutil /l <assembly_name>
gacutil /f /u <assembly_name>
shfusion.dll)
You can also view the GAC using the GAC Viewer. In Windows Explorer, navigate to %SystemRoot%\assembly. This folder displays assemblies with an "Assembly name," "Version," and "Culture" structure.
You can also access it by running shfusion.dll (e.g., regsvr32 shfusion.dll then browse to %SystemRoot%\assembly, or directly navigate to %SystemRoot%\assembly).
The GAC is generally recommended for:
For assemblies specific to a single application, it's usually better to deploy them alongside that application (e.g., in the application's bin directory) to avoid unnecessary complexity and potential versioning conflicts.