ConfigurationManager 不将设置保存到 exe.config
(我的问题与这个类似,但代码略有不同,解决方案没有对我不起作用)
我试图将设置更改保存到 app.config
:
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.AppSettings.Settings("HistoryRootDirectoryPath").Value = p_historySavingPath
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
bin 文件夹中的 exe.config
文件中没有保存任何内容,也没有保存任何内容到实际的app.config
文件。我做错了什么?
(My question is similar to this one, but the code is slightly different, and the solution doesn't work for me)
I'm trying to save settings changes to the app.config
:
Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.AppSettings.Settings("HistoryRootDirectoryPath").Value = p_historySavingPath
config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
Nothing is saved neither to the exe.config
file in bin folder, and not to the actual app.config
file. What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后发现更改保存在 .vshost.exe.config 下。
正如 Oded 提到的,这是因为代码是在 Visual Studio 进程主机下运行的。
请注意,一旦停止进程运行,更改就会恢复。
Finally ended finding the changes are being saved under .vshost.exe.config.
As Oded mentioned,that is because the code is being run under the Visual Studio process host.
Note that the changes are being reverted once you stop the process run.