Monday, September 19, 2011

Hot to Get Public Key Token of Assembly Within Visual Studio Solution( Components etc)

In Visual Studio, go to the Tools menu and choose External Tools.
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
The path of sn.exe could be change according to Visual studio version or windows version.
At my work computer i got at C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin and
C:\Program Files\Microsoft SDKs\Windows\v7.0A\bin\NETFX 4.0 Tools\ directories
in windows XP operating system.
Arguments: -Tp $(TargetPath)
Check the Use Output Window checkbox.  The final looks like this:
Create a project and sign it using a strong name key by opening properties of the project and go to the Signing section and do as in the diagram.

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

Public key token is 9589fa1be527eb6c
Just copy the last value and put it into your assembly's 5-part name.
It could be achieved by  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.

1 comment :