Assembly.GetExecutingAssembly Assembly.GetExecutingAssembly Assembly.GetExecutingAssembly Assembly.GetExecutingAssembly Method

정의

현재 실행 중인 코드가 포함된 어셈블리를 가져옵니다.Gets the assembly that contains the code that is currently executing.

public:
 static System::Reflection::Assembly ^ GetExecutingAssembly();
public static System.Reflection.Assembly GetExecutingAssembly ();
static member GetExecutingAssembly : unit -> System.Reflection.Assembly
Public Shared Function GetExecutingAssembly () As Assembly

반환

현재 실행 중인 코드가 포함된 어셈블리를 가져옵니다.The assembly that contains the code that is currently executing.

예제

다음 예제에서는 Type.Assembly 현재 실행 중인 어셈블리를 가져올 속성 형식을 기반으로 해당 어셈블리에 포함 합니다.The following example uses the Type.Assembly property to get the currently executing assembly based on a type contained in that assembly. 또한 호출을 GetExecutingAssembly 표시를 반환 하는 방법은 Assembly 동일한 어셈블리를 나타내는 개체입니다.It also calls the GetExecutingAssembly method to show that it returns an Assembly object that represents the same assembly.

using namespace System;
using namespace System::Reflection;

ref class Example
{};

void main()
{
   // Get the assembly from a known type in that assembly.
   Type^ t = Example::typeid;
   Assembly^ assemFromType = t->Assembly;
   Console::WriteLine("Assembly that contains Example:");
   Console::WriteLine("   {0}\n", assemFromType->FullName);

   // Get the currently executing assembly.
   Assembly^ currentAssem = Assembly::GetExecutingAssembly();
   Console::WriteLine("Currently executing assembly:");
   Console::WriteLine("   {0}\n", currentAssem->FullName);

   Console::WriteLine("The two Assembly objects are equal: {0}",
                      assemFromType->Equals(currentAssem));
}
// The example displays the following output:
//    Assembly that contains Example:
//       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
//    Currently executing assembly:
//       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
//    The two Assembly objects are equal: True
using System;
using System.Reflection;

class Example
{
   static void Main()
   {
      // Get the assembly from a known type in that assembly.
      Type t = typeof(Example);
      Assembly assemFromType = t.Assembly;
      Console.WriteLine("Assembly that contains Example:");
      Console.WriteLine("   {0}\n", assemFromType.FullName);

      // Get the currently executing assembly.
      Assembly currentAssem = Assembly.GetExecutingAssembly();
      Console.WriteLine("Currently executing assembly:");
      Console.WriteLine("   {0}\n", currentAssem.FullName);
      
      Console.WriteLine("The two Assembly objects are equal: {0}",
                        assemFromType.Equals(currentAssem));
   }
}
// The example displays the following output:
//    Assembly that contains Example:
//       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
//    Currently executing assembly:
//       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
//    The two Assembly objects are equal: True
Imports System.Reflection

Public Module Example
   Public Sub Main()
      ' Get the assembly from a known type in that assembly.
      Dim t As Type = GetType(Example)
      Dim assemFromType As Assembly = t.Assembly
      Console.WriteLine("Assembly that contains Example:")
      Console.WriteLine("   {0}", assemFromType.FullName)
      Console.WriteLine()
      
      ' Get the currently executing assembly.
      Dim currentAssem As Assembly = Assembly.GetExecutingAssembly()
      Console.WriteLine("Currently executing assembly:")
      Console.WriteLine("   {0}", currentAssem.FullName)
      Console.WriteLine()
      
      Console.WriteLine("The two Assembly objects are equal: {0}",
                        assemFromType.Equals(currentAssem))
   End Sub
End Module
' The example displays the following output:
'    Assembly that contains Example:
'       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
'
'    Currently executing assembly:
'       GetExecutingAssembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
'
'    The two Assembly objects are equal: True

설명

성능상의 이유로 알 수 없는 디자인 타임에 어셈블리는 현재 실행 중인 경우에이 메서드를 호출 해야 합니다.For performance reasons, you should call this method only when you do not know at design time what assembly is currently executing. 검색 하는 권장된 방법은 Assembly 현재 어셈블리를 나타내는 개체를 사용 하는 것은 Type.Assembly 다음 예제와 같이 어셈블리에서 형식의 속성을 찾을.The recommended way to retrieve an Assembly object that represents the current assembly is to use the Type.Assembly property of a type found in the assembly, as the following example illustrates.

using System;
using System.Reflection;

public class Example
{
   public static void Main()
   {
      Assembly assem = typeof(Example).Assembly;
      Console.WriteLine("Assembly name: {0}", assem.FullName);
   }
}
// The example displays output like the following:
//    Assembly name: Assembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
Imports System.Reflection

Module Example
   Public Sub Main()
      Dim assem As Assembly = GetType(Example).Assembly
      Console.WriteLine("Assembly name: {0}", assem.FullName)
   End Sub
End Module
' The example displays the following output:
'   Assembly name: Assembly1, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

현재 실행 중인 코드를 호출한 메서드를 포함 하는 어셈블리를 가져오려면 GetCallingAssembly합니다.To get the assembly that contains the method that called the currently executing code, use GetCallingAssembly.

적용 대상