2016-03-24 24 views
0

後我有節約使用ConfigurationManager中設置,這樣一個C#應用程序:ConfigurationManager中在VS2012不保存退出

public static void SaveSetting(string key, string value) 
    { 
     var configurationFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
     configurationFile.AppSettings.Settings.Remove(key); 
     configurationFile.AppSettings.Settings.Add(key, value); 
     configurationFile.Save(ConfigurationSaveMode.Full); 
     ConfigurationManager.RefreshSection("appSettings"); 
    } 

從編譯.exe文件運行,一切都很好 - application_name.exe.Config包含更新設置。

用完了VS2012,application_name.vshost.exe.Config被SaveSetting()正確保存。但是,只要我退出應用程序,application_name.vshost.exe.Config就會恢復到啓動應用程序之前的狀態 - 即使時間戳記顯示它是舊版本的配置文件。

發生了什麼事?

回答

0

vshost.exe.config僅供調試時使用。它並不打算保持其值。只要您停止運行應用程序,它將被exe.config文件替換。

+0

謝謝!這是有道理的,即使它不是我會這樣做的方式:) –

相關問題