David Bailey from RDA Corp clued me into a very slick way to obtain the public key token and blob for a signed assembly directly from within Visual Studio 2005. This is a common task for Web Part developers as we need the public key token when creating entries in the web.config among other places in SharePoint.
Previously I was opening the signed assembly and get the public key token using Lutz’s Reflector. The public key token is displayed in the footer of Reflector, like so:
The way to get the public key token using the .NET 2.0 provided utilities is to open a Visual Studio 2005 command prompt and typing: sn.exe -T [full path to strong named assembly]
However, there’s an even easier way using the external tools dialog in Visual Studio 2005 which David demonstrated in our SharePoint Developer class earlier today.
- In Visual Studio 2005, click Tools -> External Tools…
- Click Add and enter the following into the different fields as displayed in the following screenshot:
- Title: Get Public Key
- Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe
- Arguments: -Tp “$(TargetPath)”
- Uncheck all options, except *Use Output window*
Now, you have a new entry listed in the Tools menu titled Get Public Key as shown in the following screenshot:
Assuming you have a project open that has been configured to be signed when built, and you’ve built it at least one time, selecting the new Get Public Key menu item from the Tools window to get the public key token and blob in the Output window, as shown here:
Very slick! You can even take this one step further by adding a button to a toolbar by customizing your toolbar and adding a button from the Tools category. you should pick External Command # where # is the index of the external command from the External Tools window (in my screenshots above, this is External Command 3). Then you can change the name of the button to be Get Public Key as shown below:
Very cool! Thanks David!comments powered by Disqus