Many times we need to get the Public key token for a strongly named assembly in .NET. FAQ on that “how to get the public key token?”. Answer is very simple use the .NET Framework tools sn.exe. So open the Visual Studio 2008 Command Prompt and then point to the dll’s folder you want to get the public key,
Use the following command,
sn –T myDLL.dll
This will give you the public key token. Remember one thing this only works if the assembly has to be strongly signed.
C:\WINNT\Microsoft.NET\Framework\v3.5>sn -T EdmGen.exe
Microsoft (R) .NET Framework Strong Name Utility Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.
Public key token is b77a5c561934e089
That's not fonction with framwork 3.0
Thank you! Why doesn't the MSDN documentation make this obvious?
MSDN is Wiki now, so you can add your inputs there. Please feel free to add any document/notes for others.
We can find the public token key in GAC
Hello Wriju da,This was helpful for me.
I couldn't find it at first and then realized the location depends on the version. Try opening a visual studio command prompt, as it should recognize the sn command
Thanks, this tip helped me out!
Touche, very good when i needed to find the strongly typed keytoken....tyvm.
Yes, Mark's suggestion worked for me. "Try opening a visual studio command prompt, as it should recognize the sn command"
For me the executable is located in a totally different place from what you posted. For me, it's located in the following folder:
C:\Program Files\VISUALSTUDIO.2005.EN\VC (VS2005)
C:\Program Files\Microsoft Visual Studio 10.0\VC> (VS2010)
So using visual studio command prompt, which is not available in newer version will be your best bet.
The location I have specified is for EdmGen.exe not for Command Prompt. You should open the command prompt from program menu if VS
I cant get this to work with System.Web.dll
sn -T System.Web.dll . Give the error System cannot find the file specified.
WHERE WE USE THIS PUBLIC KEY TOKEN AND WHAT IS THE MAIN USE WITH IT?
Hi I found a quite easy way to do so, even with unsigned assemblies. Open Immediate Window (Alt + Ctrl + I) and write the following command
It will also provide you the version no, culture and public key
Inspired by @Amlan's comments, I am using powershell to list the info:
([system.reflection.assembly]::loadfile("c:\program files\Microsoft SQL Server\100\SDK\Assemblies\Microsoft.sqlserver.smo.dll")).FullName
This will gives out the following info
Microsoft.SqlServer.Smo, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91