Global Assembly Cache (GAC)
The Global Assembly Cache (GAC) is a repository for storing .NET assemblies that are shared across applications on a machine. It simplifies the management of assemblies, allowing for side-by-side versioning and improved file security. This guide covers how to create a .dll assembly using Visual Studio, sign it with a strong name, and install it in the GAC using both the gacutil.exe tool and Windows installer GUI. Additionally, it explains how to register the assembly in the Windows registry for both 32-bit and 64-bit systems, ensuring easy access within Visual Studio.
Global Assembly Cache (GAC)
E N D
Presentation Transcript
What is GAC • Repository containing all the assemblies of CLR • Machine wide • Assemblies shared by several applications • Where CLR is installed • C:\Windows\Microsoft.NET\assembly\GAC_MSIL
Why we have to use GAC • Adding again and again assembly in different project • Shared location • File security • Side by side versioning (under consideration) • Additional search location
How to install an assembly in GAC • Install by using the gacutil.exe tool • Recommended for developers • Install by using GUI interface of Windows installer
How to make an assembly(.dll) • Create a library project in Visual studio • Add some functions • To sign an assembly with a strong name • public/private key pair • Use this command to make a key • sn -k <keyname>.snk • It creates a key pair file “keyname.sn”
How to make an assembly(.dll) cont… • Put the key file in library project
How to install an assembly(.dll) Method -1 • Open Visual Studio Command Prompt • Use this command to register assembly • gacutil.exe –i myassembly.dll • It creates the folder with assembly • C:\Windows\Microsoft.NET\assembly\GAC_MSIL
How to install an assembly(.dll) Method -2 • Create a new setup project in same solution • Drag the assembly to the GAC folder • Build the setup project and install it • It creates the folder with assembly • C:\Windows\Microsoft.NET\assembly\GAC_MSIL
How to register an assembly(.dll) cont… • Open registry and go to this path • Create a registry key with assembly location • For 32 bit • [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\VersionMinimum\AssemblyFoldersEx\MyAssemblies]@="AssemblyLocation“ • [HKEY_CURRENT_USER\SOFTWARE\Microsoft\.NETFramework\VersionMinimum\AssemblyFoldersEx\MyAssemblies]@="AssemblyLocation"
How to register an assembly(.dll) cont… • For 64 bit operating system • [HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\VersionMinimum\AssemblyFoldersEx\MyAssemblies]@="AssemblyLocation" • [HKEY_CURRENT_USER\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\VersionMinimum\AssemblyFoldersEx\MyAssemblies]@="AssemblyLocation“
Use assembly in Visual Studio • Assembly is created under .NET column • Just right “using assembly name;” and enjoy