我可以控制.NET用户设置的位置,以避免在应用程序升级时丢失设置吗? [英] Can I control the location of .NET user settings to avoid losing settings on application upgrade?

查看:106
本文介绍了我可以控制.NET用户设置的位置,以避免在应用程序升级时丢失设置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试自定义 user.config 文件的位置。当前,它以哈希和版本号存储

I'm trying to customize the location of the user.config file. Currently it's stored with a hash and version number

%AppData%\[CompanyName]\[ExeName]_Url_[some_hash]\[Version]\

我希望与应用程序版本无关

I want to it be agnostic to the version of the application

%AppData%\[CompanyName]\[ProductName]\

可以这样做吗?意味着什么?升级后用户会从以前的版本中丢失设置吗?

Can this be done and how? What are the implications? Will the user lose their settings from the previous version after upgrading?

推荐答案

第一个问题,从技术上讲,您可以将文件放置在所需的任何位置,但是您必须自己编写代码,因为文件转到的默认位置是两个示例中的第一个。 (链接到自己的操作方式

To answer the first question, you technically can put the file wherever you want, however you will have to code it yourself, as the default place the file goes to is the first of your two examples. (link to how to do it yourself)

对于第二个问题,这取决于您如何部署应用程序。如果您通过.msi进行部署,则安装项目(创建msi的项目)的属性中有两个哈希值:升级代码和产品代码。这些决定了msi的安装方式,以及它是否升级,覆盖或在同一应用程序的任何其他版本旁边安装。

As for the second question, it depends on how you deploy the application. If you deploy via a .msi, then there are two hashes in the properties of the setup project (that the msi is built from), the 'upgrade code' and the 'product code'. These determine how the msi can be installed, and if it upgrades, overwrites, or installs beside any other version of the same application.

例如,如果您有两个版本的软件,并且它们具有不同的升级代码,则无论名称如何,它们到Windows都是完全不同的软件是。但是,如果升级代码相同,但产品代码不同,则当您尝试安装第二个msi时,它将询问您是否要升级,这时应从中复制值。从旧配置到新配置。如果两个值相同,并且版本号未更改,则新配置将与旧配置位于同一位置,并且无需执行任何操作。 MSDN文档

For instance, if you have two versions of your software and they have different 'upgrade' codes, then to windows they are completely different pieces of software regardless of what the name is. However if the 'upgrade' code is the same, but the 'product' code is different then when you try to install the 2nd msi it will ask you if you want to upgrade, at which time it is supposed to copy the values from the old config to a new config. If both values are the same, and the version number didn't change then the new config will be in the same location as the old config, and it won't have to do anything. MSDN Documentation

ClickOnce有点不同,因为它更多地基于ClickOnce版本号和URL路径,但是我发现只要您继续发布到同一位置新版本的应用程序将继续使用现有配置。 (链接到ClickOnce处理更新的方式

ClickOnce is a little bit different, because its based more off of the ClickOnce version # and URL path, however I have found that as long as you continue to 'Publish' to the same location the new version of the application will continue to use the existing config. (link to how ClickOnce handles updates)

我也知道有一种方法可以使用自定义安装脚本在msi安装期间手动合并配置,但是我不记得要执行的确切步骤...(有关如何使用web.config的操作,请参见链接)

I also know there is a way to manually merge configs during the install of the msi using custom install scripts, but I don't remember the exact steps to do it... (see this link for how to do it with a web.config)

这篇关于我可以控制.NET用户设置的位置,以避免在应用程序升级时丢失设置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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