C# 如何查看我的程序集的强名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17375759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 09:20:45  来源:igfitidea点击:

How can I see the strong name of my assembly?

c#visual-studiovisual-studio-2012.net-assemblystrongname

提问by Jeremy Holovacs

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.

我如何知道我的程序集的强名称是什么?看起来这应该是显而易见的,但我找不到任何参考。

采纳答案by Patedam

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 :

您可以使用 Reflector 或 ILSpy 等工具获取完全限定名称。选择程序集,它应该在它的顶部。对于 ILSpy 中的 XNA:

// 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

// 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.

如果不想使用这些工具,可以使用 Windows 资源管理器和 Visual Studio 命令提示符找出完全限定名称。

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

首先,右键单击Assembly DLL -> Properties -> Details。您可以在此处找到程序集的名称、版本和文化。

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

对于公钥,启动 Visual Studio 命令提示符并写入:

sn -Tp YourAssembly.dll

sn -Tp YourAssembly.dll

It will give you the public key.

它会给你公钥。

Now you can forge Fully Qualified Name.

现在您可以伪造完全限定名称。

回答by Jeremy Thompson

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. }

如果您知道文件名,则可以处理PE 标头以找到强名称签名。}

回答by keyboardP

You can use the Strong Nametool 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 Reflectoror ILSpyto find the public key token.

您还可以使用ReflectorILSpy来查找公钥令牌。

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

如果要获取程序集的全名,包括公共令牌,可以使用Assembly.FullName

Assembly.GetExecutingAssembly().FullName;