每个AppDomain允许有多少个app.config文件?
时间:2020-03-05 18:48:14 来源:igfitidea点击:
我希望如果应用程序在单个AppDomain中运行,则有一种避免自定义配置文件的方法。
解决方案
回答
来自Suzanne Cook的.NET CLR注意:
App.Config Files: As default the app config file of the default appdomain is in the process exe’s directory and named the same as the process exe + ".config". Also, note that a web.config file is an app.config - ASP.NET sets that as the config file for your appdomain. To change the config file, set an AppDomainSetup.ConfigurationFile to the new location and pass that AppDomainSetup to your call to AppDomain.CreateDomain(). Then, run all of the code requiring that application config from within that new appdomain. Note, though, that you won’t be able to choose the CLR version by setting the ConfigurationFile – at that point, a CLR will already be running, and there can only be one per process. Application configuration files are per appdomain. So, you can set a ‘dll config’ by using the method above, but that means that it will be used for the entire appdomain, and it only gets one.