Tuesday, May 18, 2010

Retrieving Public Key Token

At times we need to know the Public Key Token for a strongly named assembly (dll) in .Net. If somebody is working with SharePoint then it becomes a daily affair.

There is a good tool available called ".Net Reflector" (http://www.red-gate.com/products/reflector/) to easily get the Public Key Token. However, we can also use the .Net Framework tools sn.exe. The sn.exe would only work if the assembly has been strongly signed.

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


Example


C:\WINNT\Microsoft.NET\Framework\v3.5>sn -T ABCD.exe
Microsoft (R) .NET Framework Strong Name Utility Version 3.5.21022.8
Copyright (c) Microsoft Corporation. All rights reserved.
Public key token is d1850ec307b5340d

Note: We can also use the assembly folder(GAC) which is located at - c:\windows\assembly (in Run – write assembly) right click on the desired assembly(dll), on the assembly property we can find the public key. Further to get a dll from GAC - C:\windows\assembly\gac_msil

It is very easy to accomplish the task... isn't it... HaPpY CoDinG

Partha (Aurum)

No comments:

Post a Comment