6

这是仅对某些用户发生的问题。每当我在 Marketplace 中发布我的应用程序的新版本时,我都会收到来自用户的电子邮件,说应用程序中的所有设置都已丢失。

我自己无法重现这一点,而且我没有可以擦除 IsolatedStorage 的代码。

如果有人知道可能导致这种情况的原因,那就太好了。

4

2 回答 2

3

更新:不确定以下内容是否适用于 WP7 应用程序 - 我将把它留在这里以防万一。我只为普通应用程序尝试过这个。

您将需要“升级”旧的设置文件。

您还需要知道何时需要执行此操作(即仅在安装新版本时)。

要知道何时需要升级设置,请在设置中添加一个名为(例如)NeedSettingsUpgrade 的布尔值,并将其默认为 true。

然后在 Main() 开始附近的某处调用以下函数:

/// <summary>Upgrades the application settings, if required.</summary>
private static void upgradeApplicationSettingsIfNecessary()
{
    // Application settings are stored in a subfolder named after the full #.#.#.# version number of the program. This means that when a new version of the program is installed, the old settings will not be available.
    // Fortunately, there's a method called Upgrade() that you can call to upgrade the settings from the old to the new folder.
    // We control when to do this by having a boolean setting called 'NeedSettingsUpgrade' which is defaulted to true. Therefore, the first time a new version of this program is run, it will have its default value of true.
    // This will cause the code below to call "Upgrade()" which copies the old settings to the new.
    // It then sets "NeedSettingsUpgrade" to false so the upgrade won't be done the next time.

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

注意:您当然需要Settings.Default.Save()在程序退出之前调用,否则设置更改将不会保留。

于 2012-04-12T10:07:51.267 回答
2

我的方法是使用程序集版本号作为升级的触发器。在第一次运行时,它以 v1.0 和程序集版本号 1.0.0.0 所需的格式保存设置。当升级发生时,它将保存的设置编号 (1.0.0.0) 与升级后的装配编号 1.1.0.0 进行比较,并决定需要升级。

我发现重新部署Visual Studio并不能保证升级,有时它会卸载,重新安装,效果不佳。所以我改用Windows Phone Powertools来测试我的“升级”路径,因为它似乎可以可靠地进行升级。

于 2012-04-12T10:31:26.560 回答