感谢Is there a config type file for Visual Studio Add-In?我能够为我正在开发的Visual Studio加载项创建一个app.config文件,并具有读/写功能。
现在我无法保存在运行时对其所做的更改。我一直在运行以下测试代码,但是当我在调试中运行后查看app.config文件时,没有任何更改。
Dim pluginAssemblyPath As String = Assembly.GetExecutingAssembly().Location
Dim configuration As Configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath)
Dim test1 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.Settings.Item("Key1").Value = "Is this thing on?"
Dim test3 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.SectionInformation.ForceSave = True
configuration.Save(ConfigurationSaveMode.Modified)
答案 0 :(得分:0)
Dim pluginAssemblyPath As String = Assembly.GetExecutingAssembly().Location
'Dim configuration As Configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath)
Dim test1 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.Settings.Item("Key1").Value = "Is this thing on?"
Dim test3 As String = configuration.AppSettings.Settings.Item("Key1").Value
configuration.AppSettings.SectionInformation.ForceSave = True
configuration.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
实际的app.config不会改变,但bin文件夹中的配置文件会改变。