AppDomain.BaseDirectory Propriété

Définition

Obtient le répertoire de base qu'utilise le programme de résolution d'assembly pour détecter les assemblys.

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

Valeur de propriété

String

Répertoire de base utilisé par le programme de résolution d'assembly pour détecter les assemblys.

Implémente

Exceptions

L’opération est tentée sur un domaine d’application non chargé.

Exemples

L’exemple de code suivant crée un domaine d’application, en spécifiant un répertoire de base à utiliser lors de la recherche d’assemblys à charger dans le domaine. L’exemple utilise ensuite la propriété pour obtenir le BaseDirectory chemin d’accès du répertoire de base pour l’affichage sur la 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
open System
open System.IO

// Create application domain setup information
let domaininfo = AppDomainSetup()
domaininfo.ConfigurationFile <- Environment.CurrentDirectory + string Path.DirectorySeparatorChar + "ADSetup.exe.config"
domaininfo.ApplicationBase <- Environment.CurrentDirectory

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

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

// Display application domain information.
printfn $"Host domain: {AppDomain.CurrentDomain.FriendlyName}"
printfn $"Child domain: {domain.FriendlyName}\n"
printfn $"Configuration file: {domain.SetupInformation.ConfigurationFile}"
printfn $"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

Remarques

Cette propriété correspond à la AppDomainSetup.ApplicationBase propriété. Il peut également être récupéré à l’aide de la GetData méthode avec la chaîne « APPBASE ».

S’applique à

Voir aussi