다음을 통해 공유


AppDomainSetup.DynamicBase 속성

동적으로 생성된 파일의 디렉터리가 있는 기본 디렉터리를 가져오거나 설정합니다.

네임스페이스: System
어셈블리: mscorlib(mscorlib.dll)

구문

‘선언
Public Property DynamicBase As String
‘사용 방법
Dim instance As AppDomainSetup
Dim value As String

value = instance.DynamicBase

instance.DynamicBase = value
public string DynamicBase { get; set; }
public:
virtual property String^ DynamicBase {
    String^ get () sealed;
    void set (String^ value) sealed;
}
/** @property */
public final String get_DynamicBase ()

/** @property */
public final void set_DynamicBase (String value)
public final function get DynamicBase () : String

public final function set DynamicBase (value : String)

속성 값

AppDomain.DynamicDirectory가 있는 디렉터리를 지정하는 String입니다.

설명

AppDomain이 만들어진 경우, 동적 어셈블리를 저장하도록 Dynamic Directory라는 디렉터리를 지정할 수 있습니다. 이 디렉터리는 해당 디렉터리의 다른 부분에 있더라도 논리적으로는 ApplicationBase 아래에 있습니다.

예제

Imports System
Imports System.Reflection
Imports System.Reflection.Emit



Class ADDynamicBase
   
   ' SetDynamicBase.exe
   Overloads Shared Sub Main(args() As String)
      ' Create a new AppDomain.
      Dim setup As New AppDomainSetup()
      ' Need to set the application name before setting the dynamic base.
      setup.ApplicationName = "MyApplication"
      Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, setup)
      
      ' Tell the domain to search for assemblies in DynamicAssemblyDir.
      domain.SetDynamicBase("C:\DynamicAssemblyDir")
      
      ' Note that the actual dynamic directory has the form
      ' <DynamicBase>\<number>\<ApplicationName>, rather than
      ' simply <DynamicBase>.
      Dim dynamicDir As [String] = domain.DynamicDirectory
      ' The AssemblyBuilder won't create this directory automatically.
      If Not System.IO.Directory.Exists(dynamicDir) Then
         System.IO.Directory.CreateDirectory(dynamicDir)
      End If
      
      ' Define the dynamic assembly.
      Dim asmName As New AssemblyName()
      asmName.Name = "DynamicHelloWorld"
      Dim asm As AssemblyBuilder = AppDomain.CurrentDomain.DefineDynamicAssembly(asmName, AssemblyBuilderAccess.Save, dynamicDir)
      
      ' Define a dynamic module in the assembly.
      Dim [mod] As ModuleBuilder
      [mod] = asm.DefineDynamicModule("DynamicHelloWorld", "DynamicHelloWorld.dll")
      
      ' Define the "HelloWorld" type in the module.
      Dim typ As TypeBuilder = [mod].DefineType("HelloWorld", TypeAttributes.Public)
      
      ' Define the "SayHello" method.
      Dim meth As MethodBuilder = typ.DefineMethod("SayHello", MethodAttributes.Public, Nothing, Nothing)
      Dim il As ILGenerator = meth.GetILGenerator()
      il.EmitWriteLine("Hello World!")
      il.Emit(OpCodes.Ret)
      
      ' Complete the HelloWorld type.
      typ.CreateType()
      
      ' Save the assembly to the dynamic assembly directory.
      asm.Save("DynamicHelloWorld.dll")
      
      ' Launch MyExecutable.exe, which will load DynamicHelloWorld.dll.
      domain.ExecuteAssembly("MyExecutable.exe")
   End Sub 'Main
End Class 'ADDynamicBase
using System;
using System.Reflection;
using System.Reflection.Emit;

namespace AppDomainSnippets
{
    class ADDynamicBase
    {
        // SetDynamicBase.exe
        static void Main(string[] args)
        {
            // Create a new AppDomain.
            AppDomainSetup setup = new AppDomainSetup();
            // Need to set the application name before setting the dynamic base.
            setup.ApplicationName = "MyApplication";
            AppDomain domain = AppDomain.CreateDomain("MyDomain", null, setup);

            // Tell the domain to search for assemblies in DynamicAssemblyDir.
            domain.SetDynamicBase("C:\\DynamicAssemblyDir");
            
            // Note that the actual dynamic directory has the form
            // <DynamicBase>\<number>\<ApplicationName>, rather than
            // simply <DynamicBase>.
            String dynamicDir = domain.DynamicDirectory;
            // The AssemblyBuilder won't create this directory automatically.
            if(!System.IO.Directory.Exists(dynamicDir))
            {
                System.IO.Directory.CreateDirectory(dynamicDir);
            }

            // Define the dynamic assembly.
            AssemblyName asmName = new AssemblyName();
            asmName.Name = "DynamicHelloWorld";
            AssemblyBuilder asm = AppDomain.CurrentDomain.DefineDynamicAssembly
                (asmName, AssemblyBuilderAccess.Save, dynamicDir);

            // Define a dynamic module in the assembly.
            ModuleBuilder mod;
            mod = asm.DefineDynamicModule
                ("DynamicHelloWorld", "DynamicHelloWorld.dll");

            // Define the "HelloWorld" type in the module.
            TypeBuilder typ = mod.DefineType
                ("HelloWorld", TypeAttributes.Public);

            // Define the "SayHello" method.
            MethodBuilder meth = typ.DefineMethod
                ("SayHello", MethodAttributes.Public, null, null);
            ILGenerator il = meth.GetILGenerator();
            il.EmitWriteLine("Hello World!");
            il.Emit(OpCodes.Ret);

            // Complete the HelloWorld type.
            typ.CreateType();
            
            // Save the assembly to the dynamic assembly directory.
            asm.Save("DynamicHelloWorld.dll");

            // Launch MyExecutable.exe, which will load DynamicHelloWorld.dll.
            domain.ExecuteAssembly("MyExecutable.exe");
        }
    }
}
using namespace System;
using namespace System::Reflection;
using namespace System::Reflection::Emit;

// SetDynamicBase.exe
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   
   // Create a new AppDomain.
   AppDomainSetup^ setup = gcnew AppDomainSetup;
   
   // Need to set the application name before setting the dynamic base.
   setup->ApplicationName = "MyApplication";
   AppDomain^ domain = AppDomain::CreateDomain( "MyDomain", nullptr, setup );
   
   // Tell the domain to search for assemblies in DynamicAssemblyDir.
   domain->SetDynamicBase( "C:\\DynamicAssemblyDir" );
   
   // Note that the actual dynamic directory has the form
   // <DynamicBase>\<number>\<ApplicationName>, rather than
   // simply <DynamicBase>.
   String^ dynamicDir = domain->DynamicDirectory;
   
   // The AssemblyBuilder won't create this directory automatically.
   if (  !System::IO::Directory::Exists( dynamicDir ) )
   {
      System::IO::Directory::CreateDirectory( dynamicDir );
   }

   
   // Define the dynamic assembly.
   AssemblyName^ asmName = gcnew AssemblyName;
   asmName->Name = "DynamicHelloWorld";
   AssemblyBuilder^ asmb = AppDomain::CurrentDomain->DefineDynamicAssembly( asmName, AssemblyBuilderAccess::Save, dynamicDir );
   
   // Define a dynamic module in the assembly.
   ModuleBuilder^ mod;
   mod = asmb->DefineDynamicModule( "DynamicHelloWorld", "DynamicHelloWorld.dll" );
   
   // Define the S"HelloWorld" type in the module.
   TypeBuilder^ typ = mod->DefineType( "HelloWorld", TypeAttributes::Public );
   
   // Define the S"SayHello" method.
   MethodBuilder^ meth = typ->DefineMethod( "SayHello", MethodAttributes::Public, nullptr, nullptr );
   ILGenerator^ il = meth->GetILGenerator();
   il->EmitWriteLine( "Hello World!" );
   il->Emit( OpCodes::Ret );
   
   // Complete the HelloWorld type.
   typ->CreateType();
   
   // Save the assembly to the dynamic assembly directory.
   asmb->Save( "DynamicHelloWorld.dll" );
   
   // Launch MyExecutable.exe, which will load DynamicHelloWorld.dll.
   domain->ExecuteAssembly( "MyExecutable.exe" );
}

.NET Framework 보안

플랫폼

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

참고 항목

참조

AppDomainSetup 클래스
AppDomainSetup 멤버
System 네임스페이스