简体   繁体   中英

read from app.config instead of dll.config

I have simple console application. In application there is app.config and i have defined few settings which i fetch using ConfigurationManager class like below

 var setting = ConfigurationManager.AppSettings[key]

This works ok when i am debugging on local env. Now when i deploy this code to develepment server then it reads setting from dll.config instead of app.config. I tried to google but i am not able to find any clue.

Is it possible to change behaviour to read from app.config always? The reason i am asking is because i have added transformation for app.config. So for Dev server its called app.DevServer.config and it has some specific settings.

Yes, you can manually read your app.config file with code like this:

    var configMap = new ExeConfigurationFileMap { ExeConfigFilename = "app.DevServer.config" };
    var config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None, true);
    var setting = config.AppSettings.Settings[key];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM