3

At first I had some userdefined settings stored in my app.config file, under appSettings. These are properties the user can change during runtime. The first problem I've got is when I deploy my application with ClickOnce it overwrites the app.config file and the user has lost his personal settings.

Then I moved the properties to the settings.settings file (= usersettings section in app.config) as I found on the internet that this section doesn't get overwritten when deploying with ClickOnce. Nah, it does.. Settings.Settings properties are:

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

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

Thx!

4

1 回答 1

6

当使用 ClickOnce 部署新版本的应用程序时,此方法会复制先前安装的设置。因此,用户所做的任何用户定义设置都将被复制,因此在更新后可用。我对此进行了测试,它对我有用。

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

ApplicationSettingsBase.Upgrade 方法 MSDN

StackOverflow 上的其他问题

于 2013-01-21T10:59:10.777 回答