Dan Gilleland posted on October 05, 2010 01:06
Recently, I ran into the situation where I needed to have an assembly signed with a strong name key file. The assembly was a wizard that I needed in a Visual Studio template (to gather additional information for running the template). That task was pretty easy: just open the project’s properties, click on the Signing tab, and make a new strong name key file. Give the file a name and a password, and it’s done. The results are a clean .pfx (Personal Information Exchange) file that is password secured.
But, sensing the need for some unit tests to manage the wizards changes in the future (and I was pretty sure it would morph over time), I didn’t want to make my internal class public just to satisfy unit tests, especially since some of those internal classes played with file I/O. I wanted a fairly secure assembly with a minimal exposure to public access (since the wizard would wind up in other people’s GAC).
The answer, of course, was to apply the [InternalsVisibleTo()] attribute on my wizard. Since my wizard was signed, my unit test project needed to be signed as well.
When I looked into the MSDN documents to see how to do this, I was presented with the Strong Name command line tool (sn). [Note: Funny and somewhat serendipitous, how putting sn in parenthesis just now in WLW, I get a nice snail icon:
] As I looked through the how/wherefore of using this tool, I didn’t see any mention of the .pfx file that gets generated when signing via the property page of the project in the IDE. A little more Googling, and I stumbled upon a comment in social.msdn about using the –p switch on sn to convert the .pfx to a .publickey. Then, I was able to use the sn tool to display the public key, and I’m ready to roll.
So, for the sake of those who need detailed steps (and for myself, when memory fails me in the coming months), here’s the steps for a simple demo pair of projects:
TBA
Bibliography: