gpt4 book ai didi

c# - 在运行时更改 appconfig

转载 作者:行者123 更新时间:2023-11-30 15:00:50 25 4
gpt4 key购买 nike

我正在尝试使用以下代码在运行时更新 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 。修改保存在那里。

关于c# - 在运行时更改 appconfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15137464/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com