次の方法で共有


Getting Public Key Token of Assembly Within Visual Studio

I am in training this week with Andrew Connell (by far the best SharePoint training I have ever attended), learning about SharePoint development.  As I get started with my deep dive into learning SharePoint, something that comes up a lot is the need to find the public key token of the current .NET assembly.  He just showed a great shortcut.

In Visual Studio, go to the Tools menu and choose External Tools.

image

That brings up a new dialog window.  Click the Add button and add the following:

Title: Get &PublicKeyToken

Command: C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\sn.exe

Arguments: -Tp $(TargetPath)

Check the Use Output Window checkbox.  The final looks like this:

image

Create a project and sign it using a strong name key.  Then choose Tools / Get PublicKeyToken, and in the output window you will see something like the following:

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

Public key is
0024000004800000940000000602000000240000525341310004000001000100d59451ff2ed310
447372c4d689f24dcece5aaaef6dddaffc3e43c36a9235586b33ec9e3121ad844ee521bd76fbc0
9a9a357bfeec32d87d8cd1278cd7697667263724e6ff1712e5ee3054542cfbb11b9241da118fbd
c1df7439ba13db77b63f8bf557c7f081946c02e32884c82806e0e95667e879d15b9a2912012398
76e0efa7

Public key token is 9589fa1be527eb6c

Just copy the last value and put it into your assembly's 5-part name.

Funny, I just got in the habit a long, long time ago of loading ildasm, copying the public key token, and then manually removing the spaces from that value.  Or, more recently, loading up Reflector and loading the assembly just to get the public key token.  Never even thought of this time saver, just using sn.exe from Visual Studio as an external tool.

Comments

  • Anonymous
    June 27, 2008
    Kirk, Absolutely brilliant.  Like you, I didn't even think about doing this.  Certainly makes life easier for SP developers.. Thanks!

  • Anonymous
    April 29, 2009
    Part 6 of the SharePoint for Developers series is posted to Channel9, this one focusing on creating custom

  • Anonymous
    June 28, 2010
    The comment has been removed

  • Anonymous
    June 28, 2010
    The comment has been removed

  • Anonymous
    June 23, 2014
    That is perfect. Thank you thank you  :)

  • Anonymous
    July 07, 2014
    WoW  thts so helpful thank you very much :D

  • Anonymous
    August 28, 2015
    You are the man, Kirk.

  • Anonymous
    December 31, 2015
    Hi, I have a problem. I have the public token key but cannot insert it, or don't know how to insert it. Been googling for a while and didn't found yet what I need to do. I have downloaded some c# projects from sourceforge.net, I'm using visual studio 2012 profesional, and when I import a project, It says "\Eraser.Util.csproj : error : Can't find the file or asembled Microsoft.Build, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or its dependencies. System cannot find specified file."I allready have the public token key, but now I need to insert it somewhere, just need to know where and how to do this. Any help would be very appreciated