views:

33

answers:

2

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

A: 

I'm pretty sure you can't access stuff outside of your sand boxed area with a ClickOnce install.

http://msdn.microsoft.com/en-us/library/d8saf4wy.aspx

That said if I'm wrong I'd love to know the answer too :)

ShaneC
A: 

Here is a blog article from the ClickOnce product lead at Microsoft with a way to handle app.config files for different build configurations. Hope it helps.

RobinDotNet