共用方式為


AssemblyName.GetAssemblyName(String) 方法

定義

取得指定檔案的 AssemblyName

public:
 static System::Reflection::AssemblyName ^ GetAssemblyName(System::String ^ assemblyFile);
public static System.Reflection.AssemblyName GetAssemblyName (string assemblyFile);
static member GetAssemblyName : string -> System.Reflection.AssemblyName
Public Shared Function GetAssemblyName (assemblyFile As String) As AssemblyName

參數

assemblyFile
String

要傳回其 AssemblyName 之組件的路徑。

傳回

表示指定之組件檔的物件。

例外狀況

assemblyFilenull

assemblyFile 無效,如具有無效文化特性的組件。

找不到 assemblyFile

呼叫端沒有路徑探索權限。

assemblyFile 不是有效的組件。

已使用兩組不同的辨識項載入組件或模組兩次。

範例

下列範例會取得 AssemblyName 磁碟上元件的 。 除非您將字串 「MyAssembly.exe」 取代為元件 (包含路徑的檔名,否則不會執行它。如有必要,請在硬碟上) 。 或者,您可以將此範例編譯為 “MyAssembly.exe”。

#using <system.dll>

using namespace System;
using namespace System::Reflection;
int main()
{
   
   // Replace the string "MyAssembly.exe" with the name of an assembly,
   // including a path if necessary. If you do not have another assembly
   // to use, you can use whatever name you give to this assembly.
   //
   AssemblyName^ myAssemblyName = AssemblyName::GetAssemblyName( "MyAssembly.exe" );
   Console::WriteLine( "\nDisplaying assembly information:\n" );
   Console::WriteLine( myAssemblyName );
}

using System;
using System.Reflection;

public class AssemblyName_GetAssemblyName
{
   public static void Main()
   {
      // Replace the string "MyAssembly.exe" with the name of an assembly,
      // including a path if necessary. If you do not have another assembly
      // to use, you can use whatever name you give to this assembly.
      //
      AssemblyName myAssemblyName = AssemblyName.GetAssemblyName("MyAssembly.exe");
      Console.WriteLine("\nDisplaying assembly information:\n");
      Console.WriteLine(myAssemblyName.ToString());
   }
}
Imports System.Reflection

Public Class AssemblyName_GetAssemblyName
   
   Public Shared Sub Main()
      
      ' Replace the string "MyAssembly.exe" with the name of an assembly,
      ' including a path if necessary. If you do not have another assembly
      ' to use, you can use whatever name you give to this assembly.
      '
      Dim myAssemblyName As AssemblyName = AssemblyName.GetAssemblyName("MyAssembly.exe")
      Console.WriteLine(vbCrLf & "Displaying assembly information:" & vbCrLf)
      Console.WriteLine(myAssemblyName.ToString())
   End Sub
End Class

備註

只有在檔案包含元件指令清單時,才能運作。 這個方法會使檔案開啟和關閉,但元件不會新增至這個網域。

適用於