Here is my solution to get public key and public key token of a .Net assembly.
Today I needed to access an internal class from another project in my solution. For that purpose I needed to add a InternalVisibleTo attribute in the AssemblyInfo of the referenced project.
InternalVisibleTo method takes the assembly name and assembly public key as arguments. Therefore I needed to get the public key of my assembly.
To get the public key and token you can use the “sn” tool of Visual Studio.
First open the “Developer Command Prompt for Visual Studio” with Administrator privileges.
We will use the “Microsoft .NET Framework Strong Name Utility” to get the necessary information.
Run the following command:
C:\Windows\system32>sn -Tp <AssemblyTargetPath>
Assembly target path should be full path pointing at your .dll or .exe (e.g. C:\MySolution\MyProject\bin\Debug\MyApp.exe)
The result will include the Public key (hasgh algorithm: sha1) and Public key token.
Hope it helps!
Originally published at https://www.weboideas.com on March 1, 2017.