Monday, August 10, 2009

Register a DLL into GAC (Strong Named)

A strong name consists of the assembly's identity, it's simple text name, version number, and culture information (if provided), plus a public key and a digital signature. These are the following steps before you can place a dll into the GAC :

1. Generate the public key:
Use visualStudio.Net command prompt and type the following command:

sn -k keyfile1.snk
keyfile1.snk is the keyfile we are generating.

Store this key file in the bin folder of the assembly. For example:
C:\foldername\assemblyname\bin sn-k keyfile1.snk

2. Placing the keyfile into the Assembly.
Go to AssemblyInfo.vb/AssemblyInfo.cs file:
[Assembly: AssemblyKeyFile("C:\\foldername\\assemblyname\\keyfile1.snk")]

3. ReBuild the Assembly.

4. Placing the assembly into GAC

There are two ways to place the assembly into GAC.
1. Using the utility gacutil -i
Here you should give the complete path of the dll

c:\>gactutil -i c:\foldername\assemblyname\bin\assemblyname.dll

2. The second method is u can drag the .dll file from the bin folder of the assembly and drop it into GAC.
GAC is located Usually at C:\winnt\assembly or C:\windows\assembly.

No comments: