如果应用程序在单个 AppDomain 中运行,我希望有一种方法可以避免自定义配置文件。
最佳答案
来自Suzanne Cook's .NET CLR Notes :
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.
关于.net - 每个 AppDomain 允许有多少个 app.config 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45838/