Often times we need to reference an assembly in our code that requires that we specify the PublicKeyToken of that assembly. The problem is, determining the Public Key Token of an assembly isn’t as intuitive as you’d think.
This page will show you how to determine the Public Key Token of a given assembly.
If you have installed the Microsoft SDK, you will have a tool named “Strong Name Tool” (the runtime name is “sn.exe”).
The Strong Name tool helps sign assemblies with strong names. Sn.exe provides options for key management, signature generation, and signature verification.
In addition to signing your assemblies, the sn.exe tool will display the public key token for a given assembly via its “-T” switch.
Here’s how to use sn.exe to determine the PKT of an assembly:
For this example, we will use the System.Data.Linq as our assembly.
- Open a Visual Studio Command Prompt
- Determine the location of your assembly by entering “where System.Data.Linq.dll”
- Copy the directory path of the assembly
- Change the prompt’s directory location by pasting the directory path you copied in the previous step
- Execute the Strong Name Tool -T command by entering “sn -T System.Data.Linq.dll”
- The Public key token will be displayed in the command window.