2012-04-12 68 views
6

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

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

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

+0

我对你的问题也很感兴趣。测试我的应用程序时,我注意到了类似的情况当从Visual Studio运行它并锁定手机(而不是仿真器)时,有时它会清除数据库并重新创建它,有时它会更新代码而不删除数据库。 – Dante 2012-04-12 09:42:57

回答

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()程序退出之前,否则设置更改将不会被保留。

+0

因此,此代码适用于非WP7应用程序? – John 2012-04-14 18:29:50

2

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

我发现做视觉工作室的重新部署没有保证做升级,有时它做了卸载,重新安装,这不是很好。所以我更改为使用Windows Phone Powertools来测试我的“升级”路径,因为它似乎可靠地进行升级。

+0

谢谢,我会看看。但我仍然有这个问题,你有什么想法是什么造成这种情况? – John 2012-04-14 18:30:28

相关问题