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屋!