C#-应用程序配置不变 [英] C# - app config doesn't change
问题描述
我想将一些设置保存在配置文件中以备将来使用. 我正在尝试使用在所有教程中看到的常规代码-
I want to save some settings on a config file for future use. I'm trying to use the regular code that I see on all the tutorials -
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings["username"].Value = m_strUserName;
// I also tried -
//config.AppSettings.Settings.Remove("username");
//config.AppSettings.Settings.Add("username", m_strUserName);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
现在-我可以看到在运行时-调试"文件夹中的文件"... vshost.exe.config"已更改,关闭我的应用程序后仍要更改-所有更改都将被删除. 我该怎么办?
Now - I can see that on runtime - the file "...vshost.exe.config" on "Debug" folder is changes, nut when I close my application - all the changes are deleted. What can I do?
推荐答案
要使用普通exe的配置文件进行测试,请在项目属性菜单的调试"选项卡中取消选中启用Visual Studio宿主过程"复选框.这将使Visual Studio不再使用vshost.exe
文件启动,并且将使用正确的配置文件.
To test using the normal exe's config file un-check the box for "Enable the Visual Studio Hosting Process" in the "Debug" tab in the project properties menu. That will make visual studio no-longer use the vshost.exe
file to launch and the correct config file will be used.
这篇关于C#-应用程序配置不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!