Thursday 23 February 2012

How to register third party assemblies into GAC


Today, I'll present how to register the third party dll files into GAC. If you try to do so, you'll get an error saying that assembly should be strongly named. The problem is because the referenced third party dll is not signed or strongly named.
Well, here are the necessary steps how to proceed: -
  1. Open the Visual Studio Command Prompt. I know everyone can do it.
  2. Copy the dlls you want to register into the VC folder. Usually it is "c:\Program Files (x86)\microsoft visual studio 10.0\vc" in windows7. It is better to copy the dll in into the VC folder otherwise you need to provide the full path of the assembly.
  3. Create a key pair to sign the assembly – sn.exe –k key.snk . If you are not giving the path of the strong name file, it will be generated in VC folder.
  4. Disassemble the dll using ILDASM – ILDASM.exe Yourdll.dll /out=Yourdll.il . This will create a ‘Yourdll.il’ file containing the IL for the assembly. It will also extract the assembly so you will now have a folder with lots of files, you will also see a .res file containing the resources for the dll.
  5. Reassemble the dll using ILASM to sign the output with the key created above –ILASM.exe Yourdll.il /dll /out=Yourdll2.dll /key=key.snk

You should now have a signed version of the dll, you can now deploy this to the GAC either using gacutil /i Yourdll2.dll or by just dragging the dll file to c:\windows\assembly.

No comments:

Post a Comment