For .NET Core assemblies, and for .NET Framework assemblies that aren't in the global assembly cache, you can get the fully qualified assembly name in a number of ways:
You can use code to output the information to the console or to a variable, or you can use the Ildasm.exe (IL Disassembler) to examine the assembly's metadata, which contains the fully qualified name.
If the assembly is already loaded by the application, you can retrieve the value of the Assembly.FullName property to get the fully qualified name. You can use the Assembly property of a Type defined in that assembly to retrieve a reference to the Assembly object. The example provides an illustration.
If you know the assembly's file system path, you can call the static (C#) or Shared (Visual Basic) AssemblyName.GetAssemblyName method to get the fully qualified assembly name. The following is a simple example.
C#
using System;
using System.Reflection;
publicclassExample
{
publicstaticvoidMain()
{
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
You can use the Ildasm.exe (IL Disassembler) to examine the assembly's metadata, which contains the fully qualified name.
The following example shows how to display the fully qualified name of an assembly containing a specified class to the console. It uses the Type.Assembly property to retrieve a reference to an assembly from a type that's defined in that assembly.
#using <System.dll>
#using <System.Data.dll>
using namespace System;
using namespace System::Reflection;
ref class asmname
{
public:
static void Main()
{
Type^ t = System::Data::DataSet::typeid;
String^ s = t->Assembly->FullName->ToString();
Console::WriteLine("The fully qualified assembly name " +
"containing the specified class is {0}.", s);
}
};
int main()
{
asmname::Main();
}
C#
using System;
using System.Reflection;
classasmname
{
publicstaticvoidMain()
{
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
Bạn có thể tìm thấy nguồn cho nội dung này trên GitHub, nơi bạn cũng có thể tạo và xem lại các vấn đề và yêu cầu kéo. Để biết thêm thông tin, hãy xem hướng dẫn dành cho người đóng góp của chúng tôi.
Ý kiến phản hồi về .NET
.NET là một dự án nguồn mở. Chọn liên kết để cung cấp ý kiến phản hồi:
Tham gia chuỗi buổi gặp gỡ để xây dựng các giải pháp AI có thể mở rộng dựa trên các trường hợp sử dụng trong thế giới thực với các nhà phát triển và chuyên gia đồng nghiệp.