Don't overwrite the settings.settings file with clickonce

At first I had some custom settings saved in my app.config file under appSettings. These are properties that the user can change at run time. The first problem I ran into is when I deploy my application using ClickOnce it overwrites the app.config file and the user has lost their personal settings.

Then I moved the properties to the settings.settings file (= usersettings section in app.config), as I found online that this section is not overwritten when deployed with ClickOnce. No, this is so .. Settings.Settings properties:

  • Create action = content
  • Copy to = Do not copy

So how can I ensure that my personal user settings are not overwritten in either the app.config file or the settings.settings file. Or is there another way and I am doing it wrong?

thank!

+3


source to share


1 answer


This method copies settings from a previous installation when deploying a new version of the application using ClickOnce. This way, any custom settings created by the user will be copied and therefore available after the upgrade. I tested this and it works for me.

public static void UpgradeUserSettings()
{
  if (Settings.Default.upgradeRequired)
  {
    Settings.Default.Upgrade();
    Settings.Default.upgradeRequired = false;
    Settings.Default.Save();
  }
} 

      



ApplicationSettingsBase.Upgrade MSDN Method

fooobar.com/questions/55297 / ...

+6


source







All Articles