A few clarifications:
You have to call the Upgrade
method of ApplicationSettingsBase
derived class (that is normally called Settings
and is created for you by Visual Studio):
Properties.Settings.Default.Upgrade();
When/where to call the Upgrade
method? There is a simple trick you can apply: define a user setting called UpgradeRequired
(example) as bool
(the easiest way is through IDE). Make sure its default value is true
.
Insert this code snipped at the start of the application:
if (Properties.Settings.Default.UpgradeRequired)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.UpgradeRequired = false;
Properties.Settings.Default.Save();
}
So the Upgrade method will be called only after the version changes and only one time (since you disable further upgrades by setting UpgradeRequired = false
until a version change - when the property regains default value of true
).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…