Deploying assemblies to GAC

This topic may not sound too interesting too people because it is an old story. Basically in order to store anything in gac you have to strongly name an assembly. I don't  happen to put assemblies in GAC too often so I simply forget the process of strongly naming an assembly. This time around I decided to write a blog post so that I would always have something to look back into.

Say you have a class called CustomTextBox.cs in a project called ServerControls. In order to strongly name the assembly you will add another class called AssemblyInfo.cs. Strongly named assembly consists of 4 parts; assembly name,version, culture and public key token. You will define assembly culture,version and assembly key file inside AssemblyInfo.cs. Assembly key file contains the location of file with the signature to sing the assembly. Here is how it might look like.

image

In order to generate the assmeblyKeyFile you will have to go to the visual studio command prompt and run the following command.

sn -k mykey.snk

This will generate mykey.snk file that has the signature to sing the assembly. Make sure the key file exists in the same location as the assemblyinfo.cs

If you are not using visual studio you would use the following command in the command prompt to strongly name the assembly.

csc /t:library /out:CustomControls.dll AssmeblyInfo.cs CustomTextBox.cs

No Comments