10

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

4 Answers4

16

.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;
}
Vijay Chavda
  • 826
  • 2
  • 15
  • 34
1

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.

  • Could you point me to article explaining how to create a custom persistance provider for them ? –  Sep 23 '10 at 14:36
  • I don't have anything bookmarked, but a quick google search turned up this http://www.java2s.com/Code/CSharp/Windows/Savevaluetoregistery.htm –  Sep 23 '10 at 14:52
0

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.

Community
  • 1
  • 1
unclepaul84
  • 1,404
  • 8
  • 15
0

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.

justin.m.chase
  • 13,061
  • 8
  • 52
  • 100
  • 2
    Read my question again: " I want to be able to give the choice to the user in the installer". I want to give the choice. –  Sep 23 '10 at 17:04