Creating a Strongly Named Assembly – Cerberus’s First Head
Not long after you start down the path detailed in Part 2, a Wild Cerberus appears! Fortunately you have the terminology down from Part 1, so you can understand these instructions for handling Cerberus’ first head.
A Strongly Named Assembly requires 4 things, a version number, simple text name, culture info, and a public/private keypair.
This is done through the Visual Studio IDE or editing the AssemblyVersion key in the assemblyInfo.cs file. The AssemblyVersion key is the actual version of the assembly and follows the following convention [major.minor.build.revision]. I know I shouldn’t have, but I decided to call this version 220.127.116.11 since the first version was such a mess to work with. Don’t be like me…be a more responsible .NET developer.
Simple Text Name
This is just as easy as versioning. In the assemblyinfo.cs file of your project edit the AssemblyTitle key to whatever you want the simple text name to be. For example you call it “Hercules”. This can also be done through Visual Studio using the csproj editor.
This is only important for specifying…you guessed it…culture information, things like the assemblies language. Any assembly that has Culture set to anything other than the default value of neutral, will be considered a satellite assembly and will only ever be used if the user chooses to view the application in that language.
Everything talked about up until now can be done through Visual studio, which is kind of like Hercules Golden Mace, however Hercules had to wrestle Cerberus with his bare hands so I’m assuming you don’t get to use Visual Studio. That being said, all of this can be done in the assemblyInfo.cs file. I’ve included a snapshot of this file’s contents so you can be familiar with it. Note there are other fields in this file, but those shown in the image are the only fields that affect the strong name.
//General Assembly Information
[assembly: AssemblyTitle("SimpleTextName")] [assembly: AssemblyCulture("")]//This means Culture=none
//You can specify all the values or you can default the Build and Revision Numbers
//by using the '*' as shown below:
//i.e. [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("18.104.22.168")] [assembly: AssemblyFileVersion("22.214.171.124")]
You have recognized a pattern in Cerberus’ movements and now you are ready to go on the attack. All that is left to do for this head is Sign the Assembly.
Generating Keypair and Signing the Assembly
If your application already has a Keypair (*.snk file) use that and do not generate another keypair. If not, follow the instructions to generate a new keypair and sign the assembly using Microsoft’s Strong Naming tool sn.exe which yes is in the Visual Studio Developer Command Prompt, but you can also get it in the SDK for your particular version of Windows.
Boom that’s one head down and I’m finally feeling like this labor is possible for a mere mortal such as myself. The next 2 heads are much harder to deal with than this one. If you don’t have any third party dependencies, count your blessings you get two heads for the price of one, and you can skip to part 5. The rest of you unlucky adventurers have to got through part 4, which I personally found to be the most interesting part of my journey.