Assembly.GetExecutingAssembly 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
현재 실행 중인 코드가 포함된 어셈블리를 가져옵니다.
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
반환
현재 실행 중인 코드가 포함된 어셈블리를 가져옵니다.
예제
다음 예제에서는 속성을 사용하여 Type.Assembly 해당 어셈블리에 포함된 형식을 기반으로 현재 실행 중인 어셈블리를 가져옵니다. 또한 메서드를 GetExecutingAssembly 호출하여 동일한 어셈블리를 나타내는 개체를 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
설명
성능상의 이유로 디자인 타임에 현재 실행 중인 어셈블리를 모르는 경우에만 이 메서드를 호출해야 합니다. 현재 어셈블리를 나타내는 개체를 검색 Assembly 하는 권장 방법은 다음 예제와 같이 어셈블리에 있는 형식의 속성을 사용하는 Type.Assembly 것입니다.
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.