Visual Studio Tip: Get Public Key Token for a Strong Named Assembly

I can't remember where I picked this tip up from, but I have found it useful on many occasions so I thought that I would share it.

Sometimes I need to reference the strong named assembly that I am writing in a config file or some other location, and I need to put in the fully qualified name such as:

MyNamespace.MyAssembly, version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

The first 3 parts are easy to get. I should know the name, version, and culture for the assembly since I am writing it. The part that can be a little harder to locate is the Public Key Token for my signed assembly. One common way to do this is to use Reflector to open my assembly and get the token (actually, Reflector will give you the entire fully qualified name as in the example above).  For me, that is just too much work.  If I have the project in Visual Studio already, I would much rather just click a menu item in Visual Studio to get the result.  Here is how that can be set up:

In Visual Studio, go to the Tools menu and click the External Tools menu item. This will bring up the External Tools dialog.  The image below shows the information that I have added to add a new menu item called 'Get SN Token'.

External Tools Dialog 

The command is the path to sn.exe which can be in different places depending on your VS version.  The easiest way to find it is to open a VS Command Prompt and type "where sn.exe".  The arguments field is set to -T and then the $(TargetPath) variable.  The "Use Output Window" option is checked so that the results will be shown in the VS output window.  After clicking OK, this will be enabled as a menu item as shown below.

VS Tools Menu 

The output for this command will be displayed in the output window. This also works if you have multiple projects in the same solution. 
Just highlight the project in Solution Explorer and then click the menu

Output Window 

Comments (48)
  1. Jeremiah Clarke has an awesome post about how to set up Visual Studio to retrieve the public key for

  2. Marty says:

    Great tip! Thanks heaps

  3. Scott says:

    This is the very definition of sublime <grin>!  Thanks.

  4. digiChart Developer says:

    Hey, Jerimiah. Just wanted to thank you for the tip… I’d still be looking for the PublicKeyToken had I not stumbled across your post…

  5. Jay says:

    Very helpful and easy to follow, it took me 1min to find out my PublicKeyToken. Thanks

  6. Dharam says:

    Really you saved me lot of time

    Many thanks

  7. BMW says:

    I couldn’t find the Get SN Token on External Tool. What’s VS version do you demo?

  8. BMW,

     This post shows how you can add the ability to get the token to the list of external tools.  It is not built-in to any version of VS.


  9. FRED says:

    Having some probs in VS2005, with the instruction

       open a VS Command Prompt and type "where sn.exe"….

    I assume this refers to the VS Command Window, but when I type it in, I get:

        Command "where" is not valid.

    Any thoughts / help


  10. Fred says:

    Ok – cracked it

    – I was wrong in my assumption about "VS Command Window"

    – it was exactly as it stated " VS Command Prompt"

       – I found this from the Windows Start Menu, via Visual Studio / Visual Studio Tools

  11. Sander says:

    Great tip, elegant solution…


  12. Mike Rand says:

    Well done! This trick will save me time!

  13. Them Pham says:

    Cool trick one. Thanks for your sharing

  14. dirq says:

    This is awesome and is really helpful.  Thanks!

  15. Guy says:

    This guy is a genus. Why the in world MS did not include this I have know idea.

  16. Lee says:

    Thanks for documenting this trick; big time saver!

  17. Steve Cooper says:

    This is also nice if you use the -Tp parameter — it’ll show you the public key as well as the key token, like so;

       Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.30729.1

       Copyright (c) Microsoft Corporation.  All rights reserved.

       Public key is






       Public key token is 74786c738e63f883

  18. albertito says:

    I’ve used: -T $(ItemPath)

    This way I can select the library I want to 🙂

    I hope it is util for yours 😉

  19. JK says:

    Very useful and time saving. thanks.

  20. andreas says:

    Thanks for this post. It was a great help to me.

  21. George Egonut says:

    Great tip! This will save me loads of time.

  22. Yahbing says:

    Just want to say a quick thank you. Your tip worked perfectly for me in VS08.

  23. Jules says:

    Don’t know how you figure this stuff out but thanks for saving me a bunch of time!

  24. Clem says:

    When I run this, it says Public key for assembly '(null') was invalid.  even though i generated a key.

  25. jlb says:

    I bow to your greatness – Thanks

  26. Windows Server 2008 R2 (x64) + Visual Studio 2010 Path says:

    Program Files (x86)Microsoft SDKsWindowsv7.0Abinsn.exe


  27. Ryan Rodemoyer says:

    Worked great in Visual Studio 2005. Thanks!

  28. bts says:

    Thanks a lot!

  29. Sejton Windows Server 2003 Enterprice Edition (x86) + Visual Studio 2008 says:

    Windows Server 2003 Enterprice Edition (x86) + Visual Studio 2008

    Path:  C:Program FilesMicrosoft SDKsWindowsv6.0ABinsn.exe

  30. Sonja says:

    Thanks for the tip! 🙂

  31. David Newcomb says:

    You could save yourself a step by adding the command as a post build step so the public key token will be displayed in the output of the build (if the build is successful).

    Right-click on Project->Build Event and fill in post-build event command line.

  32. Dan says:

    Brilliant Tip, thanks.

  33. Stephen says:


  34. Arnold says:


  35. Yasir Miraj says:

    Great work!!!

  36. Vini says:

    Great tip

  37. JD says:

    Seems a bit over kill to have a menu item solely for public token, but i like it!

  38. I must be too stupid says:

    how do i get the token of my file of my chosing?

  39. Ashutosh Bhawasinka says:

    You can also use a UI based tool from

  40. pachu says:

    nice post..But I could not find sn.exe in bin folder…help me..!!!

  41. Pachu says:

    this below output i got……. plz help…..

    Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.1

    Copyright (c) Microsoft Corporation.  All rights reserved.

    Usage: sn [-q|-quiet] <option> [<parameters>]


     -c [<csp>]

       Set/reset the name of the CSP to use for MSCORSN operations.

     -d <container>

       Delete key container named <container>.

     -D <assembly1> <assembly2>

       Verify <assembly1> and <assembly2> differ only by signature.

     -e <assembly> <outfile>

       Extract public key from <assembly> into <outfile>.

     -i <infile> <container>

       Install key pair from <infile> into a key container named <container>.

     -k [<keysize>] <outfile>

       Generate a new key pair of the specified size and write it into <outfile>.

     -m [y|n]

       Enable (y), disable (n) or check (no parameter) whether key containers

       are machine specific (rather than user specific).

     -o <infile> [<outfile>]

       Convert public key in <infile> to text file <outfile> with comma separated

       list of decimal byte values.

       If <outfile> is omitted, text is copied to clipboard instead.

     -p <infile> <outfile>

       Extract public key from key pair in <infile> and export to <outfile>.

     -pc <container> <outfile>

       Extract public key from key pair in <container> and export to <outfile>.

     -Pb [y|n]

       Enable (y), disable (n) or check (no parameters) the CLR policy allowing

       trusted applications to bypass strong name signature verification on their



       Quiet mode. This option must be first on the command line and will suppress

       any output other than error messages.

     -R[a] <assembly> <infile> [-ecma]

       Re-sign signed or partially signed assembly with the key pair in <infile>.

       If -Ra is used, hashes are recomputed for all files in the assembly.

       If -ecma is used, infile is treated as the real key for ECMA signing.

     -Rc[a] <assembly> <container> [-ecma]

       Re-sign signed or partially signed assembly with the key pair in the key

       container named <container>.

       If -Rca is used, hashes are recomputed for all files in the assembly.

       If -ecma is used, container is treated as the real key for ECMA signing.

     -Rh <assembly>

       Re-compute hashes for all files in the assembly.

     -t[p] <infile>

  42. Muhammad Hassan suger millils colony says:

    very good and thanks good luck

  43. brantdanger says:

    Thank you. I needed this information.

  44. musa says:

    click the link and start an online job to earn by doing simple task

  45. Frediano says:

    Super.    I modified the args slightly as shown:

    -T $(BinDir)$(CurText).dll

    So in my web.config, if the assy is copied locally to bin, I can just highlight the assy name and this will work for any assy in the bin dir, not just the project target.

  46. thank you! Very useful post!

  47. DougHuras says:

    Very Sweet!  Works like a charm.

Comments are closed.

Skip to main content