by aldous
Fri, June 12 2009 18:20
In development, it’s common to sign our assemblies to make it safe. But before you can use your signed assemblies and make entries in your web.config or app.config you need to obtain information from your assembly such as the Public Token Key. There are many tools out there that you can download and use such as the .Net Reflector which I used previously. However, most of the time we need the easy way without downloading any utilities to expose the public token key.
In .Net 2.0 provided utilities you can use the tool called “sn.exe” (sn stands for “strong name”). So from Visual Studio command prompt you need to type:
sn.exe -T <assembly_name>
Yet, there's even much easier way to get the public token key by using the external tools in Visual Studio. Here’s a few easy steps to make it work:
- In Visual Studio main menu click on Tools -> External Tools.
- Click the Add button in the External Tools dialog box then enter the following details.
- Title: Get Public Token Key
- Command: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe
for VS 2008 the path is "C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\sn.exe"
- Arguments: -Tp "$(TargetPath)"
- Check the option Use Output window

- After you click OK, you should now see a new entry called Get Public Token Key listed in the Tools menu.

- Now, when you have a project open and signed, and you already build it at least once. Going to the Tools menu and selecting the Get Public Token Key item will give you the public token key and the blob in the output window. See the screenshot below:

This trick works with Visual Studio 2003, 2005 and 2008.