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

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

问题描述

一开始我还保存在我的app.config文件中一些用户定义的设置,下的appSettings。
这些属性的用户可以在运行时改变。
的第一个问题,我所得到的是,当我部署我的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部分),因为我是使用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:


  • 构建行动=含量

  • 复制到=不要复制

所以,我怎么能做到,我的用户的个人设置不会被覆盖,无论是在应用程序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?

THX!

推荐答案

该方法将文件从以前的安装与部署的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

other问题上StackOverflow的

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

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