I am trying to get a (ClickOnce deployed) application to read the non-default config file, depending on an environment variable set on the
_envName = System.Environment.GetEnvironmentVariable("ENV");
if (_envName == null)
throw new Exception ("The ENV environemnt variable must be set");
string envFileName = "app." + _envName.ToLower() + ".config";
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.File = envFileName;
config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection("AppSettings");
This doesn't work! i.e. if the env varibale ENV is set to dvlp, the code runs, but values in the file app.dvlp.config are not accessible.
Can anyone see why this doesn't work? Or suggest a way I can have separate files, app.xxx.config for each environment / machine and have them used accordingly.
This really ought to be much more simple.
Thanks
Ryan