C# 如何找到程序集的完全限定名称?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/658446/
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-04 12:11:30  来源:igfitidea点击:

How do I find the fully qualified name of an assembly?

c#deploymentassembliesstrongname

提问by inspite

How do I find out the fully qualified name of my assembly such as:

如何找出我的程序集的完全限定名称,例如:

MyNamespace.MyAssembly, version=1.0.3300.0, 
Culture=neutral, PublicKeyToken=b77a5c561934e089

I've managed to get my PublicKeyToken using the sn.exein the SDK, but I'ld like to easily get the full qualified name.

我已经设法使用sn.exeSDK 中的获得了我的 PublicKeyToken ,但我想轻松获得完整的限定名称。

采纳答案by Hallgrim

If you can load the assembly into a .NET application, you can do:

如果您可以将程序集加载到 .NET 应用程序中,您可以执行以下操作:

typeof(SomeTypeInTheAssembly).Assembly.FullName

If you cannot then you can use ildasm.exe and it will be in there somewhere:

如果你不能,那么你可以使用 ildasm.exe,它会在某个地方:

ildasm.exe MyAssembly.dll /text

回答by Richard Slater

If you load the assembly (DLL, EXE, etc.) in Reflectorit will tell you the full strong name at the bottom.

如果您在Reflector 中加载程序集(DLL、EXE 等),它会在底部告诉您完整的强名称。

回答by joshua.ewer

Couple ways.

夫妇的方式。

In code:

在代码中:

Assembly.FullNamee.g.

Assembly.FullName例如

typeof(Thingy).Assembly.FullName

or, if its an installed assembly, from the GAC using the steps in this post on msdn.

或者,如果它是已安装的程序集,则使用msdn 上这篇文章中的步骤从 GAC 获取。

回答by Dave Van den Eynde

Use Assembly.GetExecutingAssembly()to get the current assembly, use Assembly.GetEntryAssembly()to get the assembly that started it all, or use Assembly.GetCallingAssembly()to get the assembly of the code that called your function (one up in the stack).

使用Assembly.GetExecutingAssembly()获取当前程序集,使用Assembly.GetEntryAssembly()获取启动它的程序集,或使用Assembly.GetCallingAssembly()获取调用您的函数的代码的程序集(在堆)。

Once you have the right assembly, use the FullName property, as indicated in other answers.

获得正确的程序集后,请使用 FullName 属性,如其他答案中所示。

回答by Per Noalt

Also if you're looking for the Fully Qualified Name for an assembly already in the GAC you can launch a Visual Studio Command Prompt (easiest way to set the correct paths) and use gacutil /lto list all assemblies with their respective FQNs. Use gacutil /l <yourassemblyname>to filter the list to more easily find what you're looking for.

此外,如果您正在寻找已在 GAC 中的程序集的完全限定名称,您可以启动 Visual Studio 命令提示符(设置正确路径的最简单方法)并用于gacutil /l列出所有程序集及其各自的 FQN。使用gacutil /l <yourassemblyname>该名单中筛选更容易地找到你要找的内容。

回答by csharpfolk

You can also use open source ILSpy, after you load your assembly it's full name will be diplayed in comments at the top of code window

您也可以使用开源ILSpy,加载程序集后,它的全名将显示在代码窗口顶部的注释中

回答by Daren Thomas

Late to the party, but googled some more about this issue and found this page:

聚会迟到了,但在谷歌上搜索了更多关于这个问题的信息并找到了这个页面:

He describes a powershell function that can do this. So. I've never ever used powershell before, but I thought I'd give it a try:

他描述了一个可以做到这一点的 powershell 函数。所以。我以前从未使用过 powershell,但我想我会尝试一下:

C:\> cd PATH_TO_ASSEMBLY   
C:\PATH_TO_ASSEMBLY>powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS C:\PATH_TO_ASSEMBLY> [System.Reflection.AssemblyName]::GetAssemblyName('System.Data.SQLite.dll').FullName
System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139
PS C:\PATH_TO_ASSEMBLY>

This does the trick mentioned in other answers by using code, except you don't have to create a project to do this - just type away at the prompt ;)

这通过使用代码完成了其他答案中提到的技巧,除非您不必创建项目来执行此操作 - 只需在提示符下输入即可;)

回答by uli78

JetBrains dotPeekor Telerik JustDecompileare quite good. Just open the DLL and you have the name right away.

JetBrains dotPeek或 Telerik JustDecompile都相当不错。只需打开 DLL,您就可以立即获得名称。

回答by David Clarke

This is a shameless copy-paste from I Note It Downand is a simple way to get the FQN for the project output:

这是I Note It Down的无耻复制粘贴,是获取项目输出 FQN 的简单方法:

Open Visual Studio
Go to Tools –> External Tools –> Add
    Title: Get Qualified Assembly Name
    Command: Powershell.exe
    Arguments: -command "[System.Reflection.AssemblyName]::GetAssemblyName(\"$(TargetPath)\").FullName"
    Check "Use Output Window".

The new tool appears under Tools –> Get Qualified Assembly Name. When the menu item is selected, the assembly name is given in the output window.

新工具出现在 下Tools –> Get Qualified Assembly Name。选择菜单项后,程序集名称将在输出窗口中给出。

回答by Scott Stafford

Being old-school and liking cmd better than powershell, I wrote myself this batch script to do it:

作为老派并且比powershell更喜欢cmd,我自己写了这个批处理脚本来做到这一点:

@REM fqn.bat <dll_path>
powershell -command "([system.reflection.assembly]::loadfile('%~f1')).FullName"

The %~f1expands the first parameter to be an absolute path, so running:

%~f1扩展的第一个参数是绝对路径,因此在运行:

fqn mydll.dll 

Will print the fully-qualified name you want.

将打印您想要的完全限定名称。