更新本地 app.config 中的值
我有一个 exe 可以从其本地 app.config
文件中读取一些值:
TargetDate = ConfigurationManager.AppSettings.Get("ThresholdDate");
// and try to update with the current date
ConfigurationManager.AppSettings.Set("ThresholdDate", "2011-09-01");
我认为它可以工作一次,但我根本没有看到 app.config
得到更新现在。
I've got an exe that reads some values from its local app.config
file:
TargetDate = ConfigurationManager.AppSettings.Get("ThresholdDate");
// and try to update with the current date
ConfigurationManager.AppSettings.Set("ThresholdDate", "2011-09-01");
I thought it worked once, but am not seeing the app.config
getting updated at all now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想你可以尝试这样的事情:
我不确定更改配置值的语法,但我之前已经完成了
Add
并且我知道你可以进行删除,所以我想你可以做一个删除和添加的组合如下:I think you can try something like this:
I am not sure abt the syntax for changing the config value but I have done an
Add
before and I know you can do a remove so I guess you could do a combination of remove and add like this:看这里:如何答案是使用 C# 更改 App.config 文件运行时 - 在 Visual Studio IDE 中运行时,您将看不到 /bin/appname.exe.config 中保留的值。实际上,您必须进入 bin 目录并运行 exe。
所以这段代码实际上可以工作,只是不在调试模式下:
Looking here: How to change App.config file run time using C# is the answer - while running in the visual studio IDE, you will not see the values persisted in the /bin/appname.exe.config. You actually have to go into the bin directory and run the exe.
So this code actually works, just not in debug mode:
这仅在您不处于调试模式时才有效。尝试在 /debug/appName.exe 中运行 yung 代码,您将看到 appName.exe.config 中的更改,
欢呼!
this will work only while your not in debuging mode. try to run yung code in /debug/appName.exe and the you will se the changes in appName.exe.config
cheers!