Andrew Connell [MVP MOSS]
1418 Posts |  40 Articles |  3755 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
SharePoint Quick Links
Article Categories
Archives
Post Categories


Add to Technorati Favorites

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 <SafeControl /> 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:

DavidBailey.SharePoint.TipsTricks.Reflector
Obtaining public key token using Reflector

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.

  1. In Visual Studio 2005, click Tools -> External Tools...
  2. 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\

DavidBailey.SharePoint.TipsTricks.ExternalTools
Creating an external tool in Visual Studio 2005
(click to enlarge)

Now, you have a new entry listed in the Tools menu titled Get Public Key as shown in the following screenshot:

DavidBailey.SharePoint.TipsTricks.ToolsMenu
Get Public Key menu item in the Visual Studio Tools menu
(click to enlarge)

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:

DavidBailey.SharePoint.TipsTricks.OutputWindow
Results of Get Public Key menu item in the output window

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:

DavidBailey.SharePoint.TipsTricks.Toolbar
Custom button Get Public Key on the toolbar

Very cool! Thanks David!

Technorati: ,

posted on Friday, September 15, 2006 4:04 PM

Feedback

# re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 9/18/2006 6:32 AM Jannik Anker
Gravatar Hey Andrew,

Just wanted to say that this trick is not just for VS2005 - I just tried it in VS2003, and it works great! Apart from that, cudos to David for an awesome trick :-)

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 9/19/2006 6:30 PM Steve T
Gravatar Thanks for that! I was in the class and forgot to get the details about this shortcut. Was just searching for it when I found your new blog entry.

# re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 9/19/2006 9:34 PM AC [MVP MCMS]
Gravatar Jannik - Good to know... thanks for adding this comment!
Steve - No sweat... glad you found it ala Google!

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 9/21/2006 3:27 AM Aren
Gravatar Great!! Its working fo Vs2005. Thanks for the trick.

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 11/8/2006 12:08 PM Jon Coign
Gravatar Thanks for the tip, I have been using this one for a couple of months. You can also get the public key without the line breaks by using the same technique with secutil.

Command:
C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\secutil.exe

Arguments:
-hex -s $(TargetPath)

# Using Visual Studio 2005, MakeCab.exe and MSBuild to Create Window SharePoint Services v3 Solution Files (*.WSP's) 12/20/2006 6:57 AM Andrew Connell [MVP MCMS]
Using Visual Studio 2005, MakeCab.exe and MSBuild to Create Window SharePoint Services v3 Solution Files (*.WSP's)

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 2/22/2007 8:30 AM Mc
Great tip!

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 3/19/2008 6:26 AM Sathish Kumar
Gravatar Hi,

Thanks for this trick.
It Working fine in dotnet 2005

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 5/11/2008 7:19 PM Pankaj
Gravatar AC your are great!
Awesome posting!!!

 For Visual Studio 2008 7/21/2008 2:35 PM Tim Howland
Gravatar For Visual Studio 2008, the path to sn.exe and others is:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 8/13/2008 9:38 AM Jeroen
Great! This worked for me! Thanks!

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 8/19/2008 6:14 AM prakash
Gravatar very nice. i took only 2 mins to get public key token. Very useful. thanks alot

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 9/29/2008 3:58 AM dinesh
Gravatar it's nice but i havn't get public key token
i get this

Microsoft (R) .NET Framework Strong Name Utility Version 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.

D:\Max\TestGraphics\TestGraphics\obj\Debug\TestGraphics.exe does not represent a strongly named assembly

could any one help me out

# re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 9/29/2008 7:59 AM AC [MVP MOSS]
Gravatar Dinesh-
That means you haven't signed the project. Look in the VS help for assistance to do that.

 re: VS 2005 trick for obtaining the public key token and blob of a signed assembly 10/16/2008 3:09 PM Mark
Gravatar Works in VS 2008 as well.

Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 6 and 8 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelevant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2009 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License
Site design by Heather Solomon.

 
 
MOSS WCM Training
Looking for MOSS 2007 WCM developer training? Look no further! I teach my 4-day hands-on and 5-day online WCM classes for developers I offer through the Ted Pattison Group.

Get more information on the WCM courses!


Upcoming Classes
 Hands-on WCM:
 » Las Vegas, NV
   April 20-24, 2009
 Online WCM:
 » Feb 9-13, 2009


» Register today!

JAX Office Geeks
Jacksonville Office Geeks (JOG)
JOG is a special interest group in Jacksonville, FL dedicated to bringing the local SharePoint commnity together to share tips, tricks, ideas and best practices for developing solutions on the SharePoint platform.

Next meeting details...
When:
Thur. Feb 19th, 2008
  6-8p EDT
Topic:
Cheap and Easy Wildcard Search

Speaker:
Becky Isserman

RSVP Today!


» Subscribe to the JOG newsletter