我正在尝试让(ClickOnce部署的)应用程序读取非默认配置文件,这取决于
_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");这不管用!即,如果环境变量env设置为dvlp,则运行代码,但无法访问文件app.dvlp.config中的值。
有没有人知道为什么这不起作用?或者建议一种方法,我可以有单独的文件,每个环境/机器的app.xxx.config,并相应地使用它们。
这真的应该简单得多。
谢谢
瑞安
发布于 2012-06-11 18:09:19
你传递的参数是正确的吗?我注意到你有大写的AppSettings而不是appSettings
https://stackoverflow.com/questions/3093436
复制相似问题