我正在尝试使用以下代码在运行时更新 appconfig 文件。我没有收到错误,但它没有更新我的配置文件。
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
string oldValue = config.AppSettings.Settings["Username"].Value;
config.AppSettings.Settings["Username"].Value = "NewValue";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
添加config.AppSettings.SectionInformation.ForceSave = true;
会成功的。然后你应该看看YourProject.vshost.exe.config
正如贾斯汀所说,在调试时。修改保存在那里。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)