How to give an assembly a strong name
It's not hard, but as I had to learn how to do this yesterday while creating a sharepoint webpart, I thought it might be helpful to post the steps up here.
- Open the Visual Studio.NET Command Prompt
- sn.exe -k <path for key file to be saved>\<name of key file>.snk
- I'd recommend saving the key file in the same directory as the project
- I'd also recommend giving the key file the same name as the assembly (with out the extension)
- The key file will now have been created, you should see a message like: Key pair written to <path for key file to be saved>\<name of key file>.snk
- Open the AssemblyInfo.cs file in your project
- Change the [assembly: AssemblyVersion("1.0.*")] to a "hard" version, such as [assembly: AssemblyVersion("184.108.40.206")]. This is so any references to the assemblys strong name (which contains the name, version and public key), don't break when the project is rebuilt and the version is automatically incremented.
- Change the [assembly: AssemblyKeyFile("")] to be [assembly: AssemblyKeyFile("<path for key file to be saved>\<name of key file>.snk")]
To find out the public key token for your assembly, type the following into your Visual Studio.NET Command Prompt:
sn.exe -T <path to assembly>\<assembly name>
You should see a message like:
Public key token is c9d6fafd5a623323
So now when you want to refer to your assembly by it's strong name, you'll use something like:
<assembly name>, Version=220.127.116.11, Culture=neutral, PublicKeyToken=c9d6fafd5a623323