私はついにそれを理解しました。これを行うための公開された文書化された手段がありますが、それは.Netフレームワークの奥深くに隠されています。独自の構成ファイルを変更するには、リフレクションが必要です(ConfigurationManagerを更新するだけです)。ただし、パブリックAPIを介して作成したAppDomainの構成ファイルを変更することは可能です。
私が提出したMicrosoftConnect機能のおかげで、コードは次のようになります。
class Program
{
static void Main(string[] args)
{
// Setup information for the new appdomain.
AppDomainSetup setup = new AppDomainSetup();
setup.ConfigurationFile = "C:\\my.config";
// Create the new appdomain with the new config.
AppDomain d2 = AppDomain.CreateDomain("customDomain", AppDomain.CurrentDomain.Evidence, setup);
// Call the write config method in that appdomain.
CrossAppDomainDelegate del = new CrossAppDomainDelegate(WriteConfig);
d2.DoCallBack(del);
// Call the write config in our appdomain.
WriteConfig();
Console.ReadLine();
}
static void WriteConfig()
{
// Get our config file.
Configuration c = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
// Write it out.
Console.WriteLine("{0}: {1}", AppDomain.CurrentDomain.FriendlyName, c.FilePath);
}
}
出力:
customDomain: C:\my.config
InternalConfigTest.vshost.exe: D:\Profile\...\InternalConfigTest.vshost.exe.config