An Easier Way to Find Your Assembly’s PublicKeyToken

Tags: Development, Visual Studio 2005, Visual Studio 2008

As a developer, I’m familiar with signing my assemblies in Visual Studio, then dropping them into the GAC, then right-clicking them from within the GAC and selecting “Properties,” and finally being able to see and copy the PublicKeyToken for that assembly. It’s not so bad if you have to do it every now and then, but when you sit around and write code all day, man, what a pain!

In my SharePoint adventures, I recently went through the WSS 3.0 SDK walkthrough for creating a custom ISBN field type (very nice).  However, it’s at the very beginning of this walkthrough where I found the most value.  It shows you how to add a menu item to the Tools menu to obtain an assembly’s PublicKeyToken.  This works independently of those manual steps listed above and can save you quite a bit of time.

Here are the steps to add this customization to Visual Studio.
CYA clause:  Please note that this comes from the WSS 3.0 SDK and was written for Visual Studio 2005.  Do this at your own risk.  I found it helpful.

  1. In Visual Studio, select “External Tools” from the Tools menu.
  2. In the “External Tools” dialog, click Add and enter “Get Assembly Public Key” for the Title.
  3. Fill the Command textbox by browsing to sn.exe. It is typically installed at the following location: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe.
  4. In the Arguments textbox, type the following (case sensitive) -Tp "$(TargetPath)".
  5. Enable the “Use Output window” checkbox.
  6. Click OK. The new command is added to the Tools menu.

Hooray!