【发布时间】:2025-11-21 08:50:01
【问题描述】:
我正在尝试让(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 并相应地使用它们。
这真的应该简单得多。
谢谢
瑞恩
【问题讨论】:
标签: c# configuration clickonce app-config environment