的app.config没有保存价值 [英] app.config are not saving the values
问题描述
我的的app.config
是这样的:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="foo" value=""/>
</appSettings>
</configuration>
我尝试使用下面的方法来保存富
值:
private void SaveValue(string value) {
var config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("foo", value);
config.Save(ConfigurationSaveMode.Modified);
}
但这不会改变它的价值。我没有得到一个例外。 如何解决这一问题?在此先感谢!
but this not change the value of it. and I don't get a exception. how to fix this? thanks in advance!
推荐答案
当你使用Visual Studio调试可能是&LT; yourexe&GT; .vshost.exe.config
是修改代替&LT; yourexe&GT; .exe.config
。当您构建在Release模式的应用程序只有&LT; yourexe&GT;。.exe.config
存在,并且会更新
When you are debugging with Visual Studio probably the <yourexe>.vshost.exe.config
is modified instead of the <yourexe>.exe.config
. When you build the application in Release mode only the <yourexe>.exe.config
exists and will be updated.
您code也将增加一个额外的节点配置文件。使用类似下面的code更新设置:
Your code will also add an extra node to the configuration file. Use something like the code below to update the setting:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["foo"].Value = "text";
config.Save(ConfigurationSaveMode.Modified);
这篇关于的app.config没有保存价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!