Settings.settings 文件不断重置 [英] Settings.settings File Keeps Getting Reset

查看:34
本文介绍了Settings.settings 文件不断重置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Visual Studio 2008 中调试我的项目时,我的 Settings.settings 文件在构建之间不断重置.有没有办法防止这种情况发生?

When debugging my project in Visual Studio 2008, my Settings.settings file keeps getting reset between builds. Is there a way to prevent this from happening?

谢谢.

推荐答案

好的,我找到了我真正想要的答案.基本上,您需要调用 LocalFileSettingsProvider.Upgrade.但是,由于我将使用 ClickOnce 进行部署,因此它会自动为您完成.

Okay, I found out the answer I was really looking for. Basically, you need to call LocalFileSettingsProvider.Upgrade. However, since I will be deploying using ClickOnce, it will do it for you automatically.

问:好的,但我怎么知道什么时候调用升级?

Q: Okay, but how do I know when to call Upgrade?

答:好问题.在 Clickonce 中,当您安装新版本的应用程序时,ApplicationSettingsBase 将检测到它并在加载设置时自动为您升级设置.在非 Clickonce 的情况下,没有自动升级 - 您必须自己调用 Upgrade.以下是确定何时调用升级的一种方法:

A: Good question. In Clickonce, when you install a new version of your application, ApplicationSettingsBase will detect it and automatically upgrade settings for you at the point settings are loaded. In non-Clickonce cases, there is no automatic upgrade - you have to call Upgrade yourself. Here is one idea for determining when to call Upgrade:

有一个名为 CallUpgrade 的布尔值设置,并给它一个默认值 true.当您的应用启动时,您可以执行以下操作:

Have a boolean setting called CallUpgrade and give it a default value of true. When your app starts up, you can do something like:

if (Properties.Settings.Value.CallUpgrade)
{
    Properties.Settings.Value.Upgrade();
    Properties.Settings.Value.CallUpgrade = false;
}

这将确保仅在部署新版本后第一次运行应用程序时调用 Upgrade().

This will ensure that Upgrade() is called only the first time the application runs after a new version is deployed.

参考:http://blogs.msdn.com/rprabhu/articles/433979.aspx

这篇关于Settings.settings 文件不断重置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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