若要在全局程序集缓存中发现 .NET Framework 程序集的完全限定名称,请使用全局程序集缓存工具(Gacutil.exe)。 请参阅 如何:查看全局程序集缓存的内容。
对于 .NET Core 程序集和不在全局程序集缓存中的 .NET Framework 程序集,可以通过多种方式获取完全限定的程序集名称:
可以使用代码将信息输出到控制台或变量,也可以使用 Ildasm.exe(IL 反汇编程序) 检查程序集的元数据,其中包含完全限定的名称。
如果程序集已由应用程序加载,则可以检索属性的值 Assembly.FullName 以获取完全限定的名称。 可以使用 Assembly 该程序集中定义的属性 Type 来检索对对象的 Assembly 引用。 该示例提供了一个插图。
如果知道程序集的文件系统路径,可以调用
static
(C#) 或Shared
(Visual Basic) AssemblyName.GetAssemblyName 方法来获取完全限定的程序集名称。 下面展示了一个非常简单的示例。using System; using System.Reflection; public class Example { public static void Main() { Console.WriteLine(AssemblyName.GetAssemblyName(@".\UtilityLibrary.dll")); } } // The example displays output like the following: // UtilityLibrary, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
Imports System.Reflection Public Module Example Public Sub Main Console.WriteLine(AssemblyName.GetAssemblyName(".\UtilityLibrary.dll")) End Sub End Module ' The example displays output like the following: ' UtilityLibrary, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
可以使用 Ildasm.exe(IL 反汇编程序) 检查程序集的元数据,其中包含完全限定的名称。
有关设置程序集属性(如版本、区域性和程序集名称)的详细信息,请参阅 “设置程序集属性”。 有关为程序集提供强名称的详细信息,请参阅 创建和使用强名称程序集。
示例:
以下示例演示如何向控制台显示包含指定类的程序集的完全限定名称。 它使用该 Type.Assembly 属性从该程序集中定义的类型检索对程序集的引用。
using System;
using System.Reflection;
class asmname
{
public static void Main()
{
Type t = typeof(System.Data.DataSet);
string s = t.Assembly.FullName.ToString();
Console.WriteLine("The fully qualified assembly name " +
"containing the specified class is {0}.", s);
}
}
Imports System.Reflection
Class asmname
Public Shared Sub Main()
Dim t As Type = GetType(System.Data.DataSet)
Dim s As String = t.Assembly.FullName.ToString()
Console.WriteLine("The fully qualified assembly name " +
"containing the specified class is {0}.", s)
End Sub
End Class