從應用程式定義域擷取安裝資訊
注意
本文專屬於 .NET Framework。 其不適用於較新的 .NET 實作,包括 .NET 6 和更新版本。
每個應用程式定義域的執行個體都包含這兩個屬性及 AppDomainSetup 資訊。 您可以從使用 System.AppDomain 類別的應用程式定義域擷取安裝資訊。 這個類別提供數個成員,它們會擷取應用程式定義域的組態資訊。
您也可以查詢應用程式定義域的 AppDomainSetup 物件,取得在建立時即已傳遞至定義域的安裝資訊。
下例會建立新的應用程式定義域,然後將數個成員值列印到主控台。
using namespace System;
using namespace System::Reflection;
ref class AppDomain3
{
public:
static void Main()
{
// Create the new application domain.
AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr);
// Output to the console.
Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
Console::WriteLine("New domain: " + domain->FriendlyName);
Console::WriteLine("Application base is: " + domain->BaseDirectory);
Console::WriteLine("Relative search path is: " + domain->RelativeSearchPath);
Console::WriteLine("Shadow copy files is set to: " + domain->ShadowCopyFiles);
AppDomain::Unload(domain);
}
};
int main()
{
AppDomain3::Main();
}
using System;
using System.Reflection;
class AppDomain3
{
public static void Main()
{
// Create the new application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null);
// Output to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("New domain: " + domain.FriendlyName);
Console.WriteLine("Application base is: " + domain.BaseDirectory);
Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath);
Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles);
AppDomain.Unload(domain);
}
}
Imports System.Reflection
Class AppDomain3
Public Shared Sub Main()
' Create the new application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing)
' Output to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("New domain: " + domain.FriendlyName)
Console.WriteLine("Application base is: " + domain.BaseDirectory)
Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath)
Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles)
AppDomain.Unload(domain)
End Sub
End Class
然後,下列範例集會擷取應用程式定義域的安裝資訊。 AppDomain.SetupInformation.ApplicationBase
取得設定資訊。
using namespace System;
using namespace System::Reflection;
ref class AppDomain5
{
public:
static void Main()
{
// Application domain setup information.
AppDomainSetup^ domaininfo = gcnew AppDomainSetup();
domaininfo->ApplicationBase = "f:\\work\\development\\latest";
domaininfo->ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";
// Creates the application domain.
AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr, domaininfo);
// Write the application domain information to the console.
Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
Console::WriteLine("Child domain: " + domain->FriendlyName);
Console::WriteLine();
Console::WriteLine("Application base is: " + domain->SetupInformation->ApplicationBase);
Console::WriteLine("Configuration file is: " + domain->SetupInformation->ConfigurationFile);
// Unloads the application domain.
AppDomain::Unload(domain);
}
};
int main()
{
AppDomain5::Main();
}
using System;
using System.Reflection;
class AppDomain5
{
public static void Main()
{
// Application domain setup information.
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = "f:\\work\\development\\latest";
domaininfo.ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";
// Creates the application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null, domaininfo);
// Write the application domain information to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Child domain: " + domain.FriendlyName);
Console.WriteLine();
Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase);
Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile);
// Unloads the application domain.
AppDomain.Unload(domain);
}
}
Imports System.Reflection
Class AppDomain5
Public Shared Sub Main()
' Application domain setup information.
Dim domaininfo As New AppDomainSetup()
domaininfo.ApplicationBase = "f:\work\development\latest"
domaininfo.ConfigurationFile = "f:\work\development\latest\appdomain5.exe.config"
' Creates the application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, domaininfo)
' Write the application domain information to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("Child domain: " + domain.FriendlyName)
Console.WriteLine()
Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase)
Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile)
' Unloads the application domain.
AppDomain.Unload(domain)
End Sub
End Class