Losing VB.NET “My.Settings” with each new ClickOnce deployment release

放肆的年华 提交于 2019-12-19 03:43:05

问题


I am using the built-in My.Settings functionality in VB.NET to save application settings.

This is very convenient but I notice that each time I release a new version, the settings are lost.

Why and how can I prevent it?


回答1:


You need to manually update your application settings, I use this easy method:

  • Create a boolean setting called MustUpgrade, User scope, default to True.

Then write a method to check if My.Settings requires updating, and call it's Update() method if so. Flag your settings as updated, and save. Call this somewhere in your app load. The Upgrade() method will update your Settings to the new format, and migrate your existing values over.

Sub UpgradeMySetings()
    If My.Settings.MustUpgrade Then
        My.Settings.Upgrade()
        My.Settings.MustUpgrade = False
        My.Settings.Save()
    End If
End Sub


来源:https://stackoverflow.com/questions/1702260/losing-vb-net-my-settings-with-each-new-clickonce-deployment-release

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!