Joseph Michael Pesch
VP Programming

# Get PublicKeyToken in Visual Studio

4. July 2009 18:43

The easiest way to get the PublicKeyToken of a .Net assembly is to use the SN.EXE which is typically installed in the SDK folder of the .Net framework (as shown below).

VS2005: C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe

VS2008: C:\Program Files\Microsoft Visual Studio 9.0\SDK\v3.5\Bin\sn.exe

Sample usage: SN.exe -T C:\samplepath\sampleassembly.dll

Add the following to the Post Build events: "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe" -T "\$(TargetPath)"

Then when you build the assembly it will print the public key token to the output window.

Also, you could run the assembly and put the following line in source code:

System.Diagnostics.Debug.WriteLine(System.Reflection.Assembly.GetExecutingAssembly().FullName);

Tags: ,