11

Every time a new update is released for an application with click once, the variables in the app.config file are destroyed

<userSettings>
    <app.My.MySettings>
      <setting name="Email" serializeAs="String">
        <value />
      </setting>
      <setting name="UserName" serializeAs="String">
        <value />
      </setting>
    </app.My.MySettings>
  </userSettings>

How can i prevent that?

Is there any way of feching the variables from the previous application version?

Shaul Behr
  • 36,951
  • 69
  • 249
  • 387
OrElse
  • 9,709
  • 39
  • 140
  • 253

1 Answers1

16

Do you have the "Applications should check for updates" option checked?

Have a look at Exploring Secrets of Persistent Application Settings (the section titled "Maintaining Settings Between Program Versions"):

For any settings from the current version that match settings in the prior version, this routine will import them into the current version's user.config file:

At the entry point to your program, place the following code.

if (Properties.Settings.Default.UpgradeSettings) 
{
   Properties.Settings.Default.Upgrade();
   Properties.Settings.Default.UpgradeSettings = false;
}

Note that UpgradeSettings is a boolean user setting (not application) that you need to add yourself, and you want the default value to be True.

RubberDuck
  • 11,933
  • 4
  • 50
  • 95
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • 2
    Note that UpgradeSettings is a boolean setting that you need to add yourself, and you want the default value to be True. (This is explained in the article.) – Pat Mar 04 '10 at 23:13
  • Weirdly my if statement always has reads Properties.Settings.Default.UpgradeSettings as false even when the default value is True. I had to change the setting to be named "upgrade_settings" for it to be read as True, – Matthew Lock May 11 '15 at 08:46
  • In WPF there is no **[APPname]**.Properties.Settings.Default.UpgradeSettings function but **[Applicationname]**.Properties.Settings.Default.Upgrade() exists and it is void function what should I have to @Mitch Wheat, Is it outdated in 2020, vs2019, .net 4.7 ? – Baganaakh May 22 '20 at 04:10