AppDomain.BaseDirectory AppDomain.BaseDirectory AppDomain.BaseDirectory AppDomain.BaseDirectory Property

定义

获取基目录,它由程序集冲突解决程序用来探测程序集。Gets the base directory that the assembly resolver uses to probe for assemblies.

public:
 property System::String ^ BaseDirectory { System::String ^ get(); };
public string BaseDirectory { get; }
member this.BaseDirectory : string
Public ReadOnly Property BaseDirectory As String

属性值

基目录,由程序集冲突解决程序用来探测程序集。The base directory that the assembly resolver uses to probe for assemblies.

实现

异常

在卸载的应用程序域上尝试该操作。The operation is attempted on an unloaded application domain.

示例

下面的代码示例创建一个新的应用程序域,指定在搜索要加载到域中的程序集时要使用的基目录。The following code example creates a new application domain, specifying a base directory to use when searching for assemblies to load into the domain. 然后,该示例使用BaseDirectory属性获取基目录路径,以便向控制台显示。The example then uses the BaseDirectory property to obtain the base directory path, for display to the console.

using namespace System;
using namespace System::IO;
using namespace System::Reflection;
using namespace System::Security::Policy;    // For Evidence object.

int main()
{
   
   // Create application domain setup information
   AppDomainSetup^ domaininfo = gcnew AppDomainSetup;
   domaininfo->ConfigurationFile = String::Format("{0}{1}ADSetup.exe.config", 
                                                  Environment::CurrentDirectory,
                                                  Path::DirectorySeparatorChar);
   domaininfo->ApplicationBase = String::Format("{0}", System::Environment::CurrentDirectory);
   
   //Create evidence for the new appdomain from evidence of the current application domain
   Evidence^ adevidence = AppDomain::CurrentDomain->Evidence;
   
   // Create appdomain
   AppDomain^ domain = AppDomain::CreateDomain("Domain2", adevidence, domaininfo);
   
   // Display application domain information
   Console::WriteLine("Host domain: {0}", AppDomain::CurrentDomain->FriendlyName);
   Console::WriteLine("Child domain: {0}", domain->FriendlyName);
   Console::WriteLine();
   Console::WriteLine("Configuration file: {0}", domain->SetupInformation->ConfigurationFile);
   Console::WriteLine( "Application Base Directory: {0}", domain->BaseDirectory);
   
   AppDomain::Unload(domain);
}
// The example displays output like the following:
//    Host domain: adsetup.exe
//    Child domain: Domain2
//    
//    Configuration file: C:\Test\ADSetup.exe.config
//    Application Base Directory: C:\Test
using System;
using System.IO;
using System.Reflection;
using System.Security.Policy;  

class ADSetup
{
    public static void Main()
    {
        // Create application domain setup information
        var domaininfo = new AppDomainSetup();
        domaininfo.ConfigurationFile = System.Environment.CurrentDirectory + 
                                       Path.DirectorySeparatorChar +
                                       "ADSetup.exe.config";
        domaininfo.ApplicationBase = System.Environment.CurrentDirectory;

        //Create evidence for the new appdomain from evidence of the current application domain
        Evidence adEvidence = AppDomain.CurrentDomain.Evidence;

        // Create appdomain
        AppDomain domain = AppDomain.CreateDomain("Domain2", adEvidence, domaininfo);

        // Display application domain information.
        Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
        Console.WriteLine("Child domain: " + domain.FriendlyName);
        Console.WriteLine();
        Console.WriteLine("Configuration file: " + domain.SetupInformation.ConfigurationFile);
        Console.WriteLine("Application Base Directory: " + domain.BaseDirectory);

        AppDomain.Unload(domain);
    }
}
// The example displays output like the following:
//    Host domain: adsetup.exe
//    Child domain: Domain2
//    
//    Configuration file: C:\Test\ADSetup.exe.config
//    Application Base Directory: C:\Test
Imports System.IO
Imports System.Reflection
Imports System.Security.Policy

Module Example
   Public Sub Main()
      ' Create the application domain setup information.
      Dim domaininfo As New AppDomainSetup()
      domaininfo.ConfigurationFile = Environment.CurrentDirectory + 
                                    Path.DirectorySeparatorChar + 
                                     "ADSetup.exe.config"
      domaininfo.ApplicationBase = Environment.CurrentDirectory
      
      'Create evidence for the new appdomain from evidence of the current application domain.
      Dim adEvidence As Evidence = AppDomain.CurrentDomain.Evidence
      
      ' Create appdomain.
      Dim domain As AppDomain = AppDomain.CreateDomain("Domain2", adevidence, domaininfo)
      
      ' Display the application domain information.
      Console.WriteLine(("Host domain: " + AppDomain.CurrentDomain.FriendlyName))
      Console.WriteLine(("Child domain: " + domain.FriendlyName))
      Console.WriteLine()
      Console.WriteLine(("Configuration file: " + domain.SetupInformation.ConfigurationFile))
      Console.WriteLine(("Application Base Directory: " + domain.BaseDirectory))
     
      AppDomain.Unload(domain)
   End Sub 
End Module 
' The example displays output like the following:
'    Host domain: adsetup.exe
'    Child domain: Domain2
'    
'    Configuration file: C:\Test\ADSetup.exe.config
'    Application Base Directory: C:\Test

注解

此属性与AppDomainSetup.ApplicationBase属性相对应。This property corresponds to the AppDomainSetup.ApplicationBase property. 也可以使用字符串 "APPBASE" GetData的方法来检索它。It can also be retrieved using the GetData method with the string "APPBASE".

安全性

FileIOPermission
用于访问路径本身中的信息,包括路径的格式为 "file://" 或\\"\UNC\dir" 或 "c:\\"。for access to the information in the path itself, including if the path is in the form "file://" or \\\UNC\dir or "c:\\". 关联的枚举PathDiscovery:。Associated enumerations: PathDiscovery.

适用于

另请参阅