如何在卸载时保留用户设置

发布于 2024-09-24 19:16:23 字数 236 浏览 2 评论 0原文

我正在使用 .NET 用户设置 功能并且我面临一个问题。

当卸载应用程序然后重新安装时,用户设置将丢失。

我知道这是设计使然,我希望能够在安装程序中为用户提供选择。

您能给我一些对我有帮助的文章或文档吗?

多谢

I'm using .NET user settings feature and I'm facing a problem.

When the application is uninstalled, then installed back, the user settings are lost.

I understand it's by design, and I want to be able to give the choice to the user in the installer.

Could you please give me some pointers to articles or documentation that will helps me?

Thanks a lot

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

破晓 2024-10-01 19:16:23

卸载时不会删除.NET 用户设置。事实上,该软件所有以前版本的设置都保存在Local Settings目录中。

安装新版本时,将创建新版本的设置并使用默认设置。

为了确保您的应用程序将新设置与以前的配置合并,您必须调用 Settings.Default.Upgrade() 方法。

因此,如果我们不想保留设置,解决方案是在卸载时手动删除它们。由于我需要保留以前的设置,所以我现在要做的就是创建一个名为 UpgradeRequired 的新设置,其中 true 具有默认值,然后在应用程序启动时添加以下代码:

if (Properties.Settings.Default.UpdateRequired)
{
    Properties.Settings.Default.Upgrade();
    Properties.Settings.Default.UpdateRequired = false;
}

.NET User Settings are not removed on uninstall. In fact the settings of all previous versions of the software are preserved in Local Settings directory.

When the new version is installed, a new version of the settings is created and default settings are used.

To ensure your application will merge new settings with previous configuration, you have to call Settings.Default.Upgrade() method.

So the solution is to manually remove settings on uninstall if we don't want to preserve them. Since what I needed was preserving previous settings, all I do now is creating a new setting called UpgradeRequired with true has the default value, then add this code at application startup:

if (Properties.Settings.Default.UpdateRequired)
{
    Properties.Settings.Default.Upgrade();
    Properties.Settings.Default.UpdateRequired = false;
}
少钕鈤記 2024-10-01 19:16:23

您可以将希望保存的设置写入注册表,或将它们作为 XML 文件写入不受卸载影响的位置。

You could possibly write the settings you wish to save out to the registry or write them as an XML file to a location that won't be impacted by the uninstall.

谈下烟灰 2024-10-01 19:16:23

如果您想继续使用用户设置,我建议编写一个自定义安装程序类,并实现 onUninstalling 方法,以 找到该文件并将其复制到自定义安装程序的 onInstall 方法已知的另一个位置。这样安装程序下次运行时就可以找到该文件。

If you want to keep using User Settings i would suggest writing a custom installer class, and implement the onUninstalling method, to go find the file and copy it to another location known to the onInstall method of your custom installer. So that the next time the installer runs it could find the file.

相思故 2024-10-01 19:16:23

我认为您不想在卸载后在用户计算机上实际保留数据。留下文件是一种邪恶的做法,是大忌。您应该在应用程序本身中公开一项功能,以便将这些设置导出到他们选择的位置,然后在重新安装应用程序后再次导入它,或者将这些设置同步到服务器上,以便它们在重新安装时自动可用等。卸载时不应留下任何痕迹。

I don't think you want to actually persist data on the users machine after an uninstall. Leaving files around is an evil practice, a big no-no. You should expose a feature in the application itself to either export those settings to a location of their choice and to then import it again after re-installing the app or to synchronize those settings onto a server so they're automatically available upon re-install, etc. On an uninstall you should leave no trace behind.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文