不要用 clickonce 覆盖 settings.settings 文件 [英] Do not overwrite settings.settings file with clickonce

查看:35
本文介绍了不要用 clickonce 覆盖 settings.settings 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

起初,我在 appSettings 下的 app.config 文件中存储了一些用户定义的设置.这些是用户可以在运行时更改的属性.我遇到的第一个问题是,当我使用 ClickOnce 部署我的应用程序时,它会覆盖 app.config 文件并且用户丢失了他的个人设置.

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.

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

  • 构建操作 = 内容
  • 复制到 = 不要复制

那么我如何才能实现我的用户的个人设置不被覆盖,无论是在 app.config 文件中还是在 settings.settings 文件中.或者还有其他方法,我做错了吗?

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?

谢谢!

推荐答案

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

This method copies the settings from the previous installation when deploying a new version of the application with 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 方法 MSDN

其他问题StackOverflow

这篇关于不要用 clickonce 覆盖 settings.settings 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆