How can I use several Application Configuration Files in one project?

后端 未结 1 2067
小鲜肉
小鲜肉 2021-01-04 02:03

After creating new Visual C# Console Application (.NET Framework 4.5), such project contains default App.config file.

相关标签:
1条回答
  • 2021-01-04 02:26

    It can be done using mapped config file ,

    ExeConfigurationFileMap configFileMap = 
            new ExeConfigurationFileMap();
        configFileMap.ExeConfigFilename = "App4.config"; // full path to the config file
    
        // Get the mapped configuration file
       Configuration config = 
          ConfigurationManager.OpenMappedExeConfiguration( 
            configFileMap, ConfigurationUserLevel.None);
    
       //now on use config object
    
    AppSettingsSection section = (AppSettingsSection)config.GetSection("appSettings");
    
    0 讨论(0)
提交回复
热议问题