Friday 11 July 2014

How to add assembly in gac

We can do in 3 ways

1. Using the Global Assembly Cache tool (Gacutil.exe).
You can use Gacutil.exe to add strong-named assemblies to the global assembly cache and to view the contents of the global assembly cache.
Note: Gacutil.exe is only for development purposes and should not be used to install production assemblies into the global assembly cache.
2. Using Microsoft Windows Installer 2.0.
This is the recommended and most common way to add assemblies to the global assembly cache. The installer provides reference counting of assemblies in the global assembly cache, plus other benefits.
3. Using the Mscorcfg.msc (.NET Framework Configuration Tool).
The Mscorcfg.msc (.NET Framework Configuration Tool) allows you to view the global assembly cache and add new assemblies to the cache.

Learn how to register an assembly in the GAC.
1) Create an assembly key file
2) Use the sn.exe tool to create a key file:
sn -k StrongNameFile.snk
If your path environment variables aren't set, you'll have to go to the C:\Program Files\Microsoft.NET\FrameworkSDK\Bin\ directory to run sn.exe) The filename "StrongNameFile.snk" can be any name you want.
3) Edit your assembly
Now you have to add a tag which will link your assembly key to the assembly:
using System.Reflection;
[assembly:AssemblyKeyFile("StrongNameFile.snk")]
Normally this is done in the utility AssemblyInfo.cs (vb) file.
4) Add your assembly to the GAC
Open command prompt
Steps: 1. Go to start
2.Click on run
3.Type cmd. Enter
4. type gacutil –I assembly name
Note: assembly name is the name of the assembly to install in the global assembly cache.
Ex: gacutil -i helloworld.dll