如何:确定程序集的完全限定名
若要在全局程序集缓存中查找一个程序集的完全限定名,请使用全局程序集缓存工具 (Gacutil.exe)。 请参阅如何:查看全局程序集缓存的内容。
对于不在全局程序集缓存中的程序集,可以通过多种方式获取完全限定的程序集名称:可使用代码将信息输出到控制台或变量,也可使用 Ildasm.exe(IL 反汇编程序) 检查包含完全限定名的程序集元数据。
- 如果应用程序已加载程序集,则可检索 Assembly.FullName 属性的值在以获取完全限定名。
无论 GAC 是否包含程序集,均可使用此方法。 说明如示例所示。 - 如果知道程序集的文件系统路径,则可调用静态(Visual Basic 中的Shared)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
- 可使用 Ildasm.exe(IL 反汇编程序) 检查包含完全限定名的程序集元数据。
有关设置程序集特性(如版本、区域性和程序集名称)的详细信息,请参阅设置程序集特性。 有关向程序集添加强名称的详细信息,请参阅创建和使用具有强名称的程序集。
示例
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); } }