How to change application config file name (AppName.exe.config)?

倖福魔咒の 提交于 2019-12-11 07:36:01

问题


I use My.Settings object in VB.NET, which automatically gets application setting from AppName.exe.config file. How can I store config in file with other name, not AppName.exe.config? I have several programs, all of them now uses their own .config file, but in fact they all are clones, and if I change some setting I need to edit several configs.


回答1:


This will work with <appSettings>, not sure if it works with the Settings
Design time
Put the app.config file in the solution folder so one level up from a project. For each of your projects in the solution explorer do the following
- Add > Existing Item
- Browse to app.config in solution root > Add As Link (small arrow near to the Add button)

Run time
You can use this code to load config (C#)

var fileMap = new ConfigurationFileMap(pathToConfig);  
var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);


来源:https://stackoverflow.com/questions/7216627/how-to-change-application-config-file-name-appname-exe-config

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