Changing the .NET application configuration file name

大城市里の小女人 提交于 2019-12-03 00:06:58

You can't change it. Each AppDomain instance has a fixed app.config that is set via an AppDomainSetup instance when a new app domain is created. Although you can get the setup information via AppDomain.SetupInformation it has effectively become readonly at this point.

Given this, one option may be to create a new app domain from within your Main function and configure the domain to use the app.config you require.

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @configFile);

You can force the application to read a particular config file using

System.Configuration.ConfigurationManager.OpenExeConfiguration(PATH_TO_CONFIG);

Consider putting your configuration in a XML serialized object.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!