Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to persist app.config through ClickOnce updates using ConfigurationManager?

This question describes my problem exactly, except I'm using a custom configuration section in app.config with ConfigurationManager, so the solution presented there doesn't apply...

Basically, my problem is that when ClickOnce updates the application, it installs into a different directory with the new app.config, thereby erasing any changes made. My application uses app.config to persist application settings, so this is very bad... a merged update would be excellent (similar to what is achieved in the other question), but just about anything automated would be good at this point.

Or should I just use a set location for my app.config file rather than try to use the default location?

like image 555
Matthew Scharley Avatar asked Jun 17 '09 12:06

Matthew Scharley


1 Answers

ClickOnce should maintain user settings between updates but I have had this fail once or twice for unkown reasons (and with bad results). I haven't tried a custom configuration setting but I've lost confidence in ClickOnce's ability to not overwrite settings.

The approach I'm planning to use is to manually handle ClickOnce updates rather than allowing the app. to check for updates and prompt the user to install. I've also had a couple of users who didn't accept the update and that's a pain to recover from. By manually handling the update, I hope to be able to read user settings into memory before updating, then write them back out after the update is completed. There's an ApplicationUpdated event that should serve this purpose.

Perhaps this approach could work for you as well.

Edited to add references:

  • How to: Check for Application Updates Programmatically Using the ClickOnce Deployment API
  • ApplicationSettingsBase.Upgrade Method
  • ApplicationDeployment Class

Googling for ApplicationDeployment should also help.

like image 156
Jamie Ide Avatar answered Sep 21 '22 07:09

Jamie Ide