简体   繁体   English

不要用 clickonce 覆盖 settings.settings 文件

[英]Do not overwrite settings.settings file with clickonce

At first I had some userdefined settings stored in my app.config file, under appSettings.起初,我在 appSettings 下的 app.config 文件中存储了一些用户定义的设置。 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.我遇到的第一个问题是,当我使用 ClickOnce 部署我的应用程序时,它会覆盖 app.config 文件并且用户丢失了他的个人设置。

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.然后我将属性移动到 settings.settings 文件(= app.config 中的 usersettings 部分),因为我在 Internet 上发现使用 ClickOnce 部署时该部分不会被覆盖。 Nah, it does.. Settings.Settings properties are:不,它确实...... Settings.Settings 属性是:

  • 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.那么我如何才能实现我的用户的个人设置不被覆盖,无论是在 app.config 文件中还是在 settings.settings 文件中。 Or is there another way and am I doing it wrong?还是有另一种方法,我做错了吗?

Thx!谢谢!

This method copies the settings from the previous installation when deploying a new version of the application with ClickOnce.使用 ClickOnce 部署新版本的应用程序时,此方法会复制先前安装中的设置。 So any user defined settings that the user made will be copied and thus available after the update.因此,用户所做的任何用户定义的设置都将被复制,从而在更新后可用。 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 Method MSDN ApplicationSettingsBase.Upgrade 方法 MSDN

other question on StackOverflow StackOverflow 上的其他问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM