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设置,因为它们存储在AppData文件夹中用于特定版本。基本上,我的应用程序的每个版本都是从用户设置开始的。
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.
虽然这在开发过程中是一个小麻烦,但当我接近部署/发布时,它提出了一个问题——如果我使用app.config来存储我的用户设置,用户的个性化设置是否会在每次安装修改我的应用程序版本号的补丁时被冲洗掉?如果是这样,是否有一种简单的方法可以“升级”先前版本的设置?我知道在注册中心使用HKCU是另一个选择,但我喜欢我的。设置命名空间,我想使用app.config。
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?
另一个SO问题也提出了类似的问题,尽管答案似乎并不那么清晰。设置我的MSI以要求用户升级是否足以保存这些用户级设置?
3 个解决方案
#1
36
Have you looked at ApplicationSettingsBase.Upgrade()? It allows the settings to be upgraded from a previous version using the following call:
您看过ApplicationSettingsBase.Upgrade()了吗?它允许使用以下调用从以前的版本升级设置:
My.Settings.Upgrade()
#2
7
Not sure why but neither the upgrade command or the get previous version seems to work for me. What could I be doing wrong? Do I need to call a refresh command or something. I am doing this on form load, should it be an application event?
不知道为什么,但是升级命令或之前的版本似乎都不适合我。我可能做错了什么?我需要调用refresh命令还是什么。我正在加载表单,它应该是应用程序事件吗?
UPDATE
更新
Found out why, it seems it does not work when you use a 4 digit major version number. I was using the year 2012 as the major version number. I have changed that to 12 and it works like a charm, though is no not millenium compliant. Still I got 88 years before I need to start worrying about that!
找出原因,当你使用一个4位数的主版本号时,它似乎不工作。我用2012年作为主要版本号。我把它改成了12,它就像一种魅力,虽然它不是千禧兼容的。我还有88年的时间才需要开始担心这个问题!
#3
1
Have you considered ClickOnce deployment? This topic is then covered in depth. IMO, ClickOnce is much easier both for the developer and the user.
您考虑过ClickOnce部署吗?然后深入讨论这个主题。在我看来,点击一次对开发者和用户来说都更容易。
#1
36
Have you looked at ApplicationSettingsBase.Upgrade()? It allows the settings to be upgraded from a previous version using the following call:
您看过ApplicationSettingsBase.Upgrade()了吗?它允许使用以下调用从以前的版本升级设置:
My.Settings.Upgrade()
#2
7
Not sure why but neither the upgrade command or the get previous version seems to work for me. What could I be doing wrong? Do I need to call a refresh command or something. I am doing this on form load, should it be an application event?
不知道为什么,但是升级命令或之前的版本似乎都不适合我。我可能做错了什么?我需要调用refresh命令还是什么。我正在加载表单,它应该是应用程序事件吗?
UPDATE
更新
Found out why, it seems it does not work when you use a 4 digit major version number. I was using the year 2012 as the major version number. I have changed that to 12 and it works like a charm, though is no not millenium compliant. Still I got 88 years before I need to start worrying about that!
找出原因,当你使用一个4位数的主版本号时,它似乎不工作。我用2012年作为主要版本号。我把它改成了12,它就像一种魅力,虽然它不是千禧兼容的。我还有88年的时间才需要开始担心这个问题!
#3
1
Have you considered ClickOnce deployment? This topic is then covered in depth. IMO, ClickOnce is much easier both for the developer and the user.
您考虑过ClickOnce部署吗?然后深入讨论这个主题。在我看来,点击一次对开发者和用户来说都更容易。