如何在整个文件版本更改中将更改保存在.settings / .config文件中? [英] How to persist changes in a .settings/.config file across a file version change?

查看:258
本文介绍了如何在整个文件版本更改中将更改保存在.settings / .config文件中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个使用settings.settings来存储某些用户特定设置(scope = User)的应用程序。设置会在启动时正确加载,在使用过程中进行更改,并正确保存以备下次启动。这个周期似乎没有问题。

I have created an application that uses settings.settings to store some user specific settings (scope=User). Settings are loaded correctly on startup, changed during use and saved correctly for next launch. This cycle appears to have no problems.

当我为新版本更新程序集和文件版本时,就会出现问题。这些设置将不再在启动时加载(而是使用默认值)。看来,即使启动了1.2版,从1.1版保存的配置文件也将持久存在,并且也会生成并保存一个新的配置文件(即,您可以重新启动1.1版,并且该配置文件将是从该版本保存的配置文件

The problem arises when I update the assembly and file versions for a new build. The settings are no longer loaded on startup (instead the default values are used). It also appears that a config file saved from version 1.1 will persist even if version 1.2 is launched and a NEW config file is generated and saved too (i.e. you can relaunch version 1.1 and the config file will be the config file that was saved from that version).

因此,这些设置似乎特定于程序集和/或文件的版本。还值得注意的是,在1.1版和1.2版之间,settings.settings文件或与此相关的任何其他操作都没有更改(即,我在这些不同内部版本之间所做的唯一更改是修改了版本号)。

So it appears that the settings are specific to the version of the assembly and/or file. It is also worth noting that between version 1.1 and version 1.2 there were no changes to the settings.settings file or anything else for that matter (i.e. the only change I made between these different builds was modifying the version numbers).

是否可以在版本更改期间保留这些设置?

Is there a way to persist these settings across version changes?

推荐答案

Markus Olsson已经给出了很好的答案此处

Markus Olsson has already given a pretty good answer here.

本质上,您需要使用 ApplicationSettingsBase.Upgrade()方法。

Essentially you will need to use the ApplicationSettingsBase.Upgrade() method.

这篇关于如何在整个文件版本更改中将更改保存在.settings / .config文件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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