How can I see the strong name of my assembly?
Asked Answered
C

4

41

I have a project, and I created a strong name key file for it.

How can I tell what the strong name of my assembly is? It seems this should be obvious, but I can't find any reference to it.

Cordero answered 29/6, 2013 at 1:19 Comment(0)
D
30

You can get the Fully Qualified Name by using a tool like Reflector or ILSpy. Select the assembly and it should be in top of it. For XNA in ILSpy :

// C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.dll // Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553

If you don't want to use those tools, you can figure out the Fully Qualified Name using windows Explorer and Visual Studio Command Prompt.

First, right click on the Assembly DLL -> Properties -> Details. Here you can find the name, version and Culture of your Assembly.

For the public key, launch Visual Studio Command prompt and write :

sn -Tp YourAssembly.dll

It will give you the public key.

Now you can forge Fully Qualified Name.

Dissociable answered 29/6, 2013 at 1:36 Comment(0)
A
44

You can use the Strong Name tool to determine if the assembly is strongly named. In command prompt you can do this to verify it is a strong named assembly.

sn -v "C:\MyAssemblyPath"

and to get the public token, you can do this

sn -T "C:\MyAssemblyPath"

You can also use Reflector or ILSpy to find the public key token.

If you want to get the full name of the assembly, including the public token, you can use Assembly.FullName.

Assembly.GetExecutingAssembly().FullName;
Airily answered 29/6, 2013 at 1:36 Comment(3)
so... no way to do this from Visual Studio, when the project source is loaded, then?Cordero
sn -t didn't work for me.. I got "Failed to convert key to token -- Invalid assembly public key." Paul Gillen's answer did work (-Tp) but I have to admit I'm frustrated that this cannot be done within VS. It seems silly to have to resort to a command line for a VISUAL studio tool.Cordero
Yes sorry, it should be a capital T (updated answer). It does seem odd there's no way to do it in VS but you can add sn.exe to the list of external tools and set the argument to be -T $(TargetPath), so it can be accessed directly from VS. I've just tried it and it seems to work fine and will now show the current project's public key each time the tool is selected from the Tools menu.Airily
D
30

You can get the Fully Qualified Name by using a tool like Reflector or ILSpy. Select the assembly and it should be in top of it. For XNA in ILSpy :

// C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86\Microsoft.Xna.Framework.dll // Microsoft.Xna.Framework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553

If you don't want to use those tools, you can figure out the Fully Qualified Name using windows Explorer and Visual Studio Command Prompt.

First, right click on the Assembly DLL -> Properties -> Details. Here you can find the name, version and Culture of your Assembly.

For the public key, launch Visual Studio Command prompt and write :

sn -Tp YourAssembly.dll

It will give you the public key.

Now you can forge Fully Qualified Name.

Dissociable answered 29/6, 2013 at 1:36 Comment(0)
E
4
Process[] processlist = Process.GetProcesses();

foreach(Process theprocess in processlist)
{
    string strongName = "N/A";
    try
    {
        strongName = Assembly.ReflectionOnlyLoadFrom(theprocess.MainModule.FileName).FullName;
    }
    catch
    {
        // System process?
    }
    Console.WriteLine("Process: {0} ID: {1} Strong Name: {2}", theprocess.ProcessName, theprocess.Id, strongName);

If you know the filename, you can process the PE headers to find the strong name signature. }

Edmiston answered 29/6, 2013 at 1:35 Comment(0)
L
0

Step 1: Developer Command Prompt for visual studio by searching on start menu.

Step 2:C:\Windows\system32> it will come on command promt.

Step 3:change the directory on your wish .You can give your solution directory like .cd D:\Learning\Projects\Biztalk\EAISchemas

Step 4: In command prompt, from the folder where you want to store the key file, type the following command, and ENTER:

sn /k file_name .snk

Example: sn /k ErrorHandlingProcess.snk

Lal answered 15/11, 2020 at 14:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.