How to create Strong named assemblies in .NET

This post is a very simple example of how to create strong named assemblies and use in a solution. Each project uses the same strong named key. One key is uesd for the whole solution.

Step 1:
Create the snk Key

Open the Developer Command prompt as an administrator and enter sn -k C:/yourKeyPairName.snk
StrongNameSnk01

Step 2:
Add your key to the solution base directory and link it in each project

StrongNameSnk02

Note: Add As Link and not Add!, Add copies the key.
StrongNameSnk03

Step 3:
Use the snk in the project

Open the properties of each project, and in the signing tab, sign the project with your key.
StrongNameSnk04

Now all projects are strong named. The same key is used for all projects. The assemblies can be use in the GAC or are harder to tamper with.

You can also sign assemblies, if you don’t have the source code using the Ildasm.exe tool. You should only do this if you don’t have the source code. You should not use this approach if you have the source code as this borders on a dirty hack…

If you need to sign 3rd Party assemblies in you project, maybe the 3rd party assemblies shouldn’t be used…

Links:

http://msdn.microsoft.com/en-us/library/6f05ezxy(v=vs.110).aspx

http://ryanfarley.com/blog/archive/2010/04/23/sign-a-.net-assembly-with-a-strong-name-without-recompiling.aspx

http://en.wikipedia.org/wiki/Common_Intermediate_Language#Generation

http://buffered.io/posts/net-fu-signing-an-unsigned-assembly-without-delay-signing/

http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx

http://blog.codingoutloud.com/2010/03/13/three-ways-to-tell-whether-an-assembly-dl-is-strong-named/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: