自动“升级"以前版本的 app.config 文件中的用户设置? [英] Automatically "upgrade" user settings from previous version of app.config file?

查看:20
本文介绍了自动“升级"以前版本的 app.config 文件中的用户设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我编译我的应用程序并且版本号发生变化(我有一个自动递增的内部版本号)时,我都会丢失用户配置的 app.config 设置,因为它们存储在特定版本的 AppData 文件夹中.基本上,就用户设置而言,我的应用程序的每个版本都从头开始.

Every time I compile my app and the version number changes (I have an auto-incrementing build number), I lose the user-configured app.config settings, since they're stored in the AppData folder for a specific version. Essentially, every release of my application starts from scratch as far as user settings go.

虽然这在开发过程中是一个轻微的烦恼,但它在我接近部署/发布时提出了一个问题 - 如果我使用 app.config 来存储我的用户设置,用户的个性化设置是否会在每次安装时被处理更改我的应用程序版本号的补丁?如果是这样,是否有一种简单的方法可以升级"先前版本的设置?我知道在注册表中使用 HKCU 是另一种选择,但我喜欢 My.Settings 命名空间的易用性,我想继续使用 app.config.

While this is a mild annoyance in development, it raises the question as I approach deployment/release - if I use the app.config to store my user settings, will the user's personalized settings be hosed every time they install a patch that changes the version number of my app? If so, is there an easy way to "upgrade" the settings from the previous release? I know that using HKCU in the registry is another option, but I like the ease of the My.Settings namespace, and I'd like to stay with app.config.

另一个问题提出了类似的问题,虽然答案似乎并不那么清楚.将我的 MSI 设置为要求用户升级是否足以保留这些用户级设置?

Another SO question asks something similar, though the answer doesn't seem that clear. Will setting my MSI so it asks the user to upgrade be enough to preserve these user-level settings?

推荐答案

你看过 ApplicationSettingsBase.Upgrade()?它允许使用以下调用从以前的版本升级设置:

Have you looked at ApplicationSettingsBase.Upgrade()? It allows the settings to be upgraded from a previous version using the following call:

My.Settings.Upgrade()

这篇关于自动“升级"以前版本的 app.config 文件中的用户设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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