views:

899

answers:

1

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?

+1  A: 

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:

Googling for ApplicationDeployment should also help.

Jamie Ide
Whereabouts is this ApplicationUpdated event? I can't find it in the object browser... Also, this hasn't helped the problem (although, it's a nice feature, i never liked the ClickOnce dialogs), the updates still install to a new directory, so the old app.config is lost
Matthew Scharley
re: your second link about ApplicationSettingsBase, I'm inheriting from ConfigurationSection, so this isn't an option for me is it?
Matthew Scharley
Have a look at the Deployment.Application.ApplicationDeployment class. I think I was looking at sample code when I mentioned the ApplicationUpdated event. I realize the old app.config is lost, my idea is to read in the user settings from the current config, update, then write out the user settings to the new config.
Jamie Ide
Sadly, finding where the new config is is just as hard as finding where the old config is... or is it? I can't make sense of the directory structure for clickonce apps... Mine is a full trust app, so permissions aren't an issue, if we could figure that much out
Matthew Scharley
For now I've simply settled for having an app.config in an appropriate place in %appdata%, it works and won't get touched during an update... also nets me my user based settings I wanted too, so it's a win/win situation I suppose...
Matthew Scharley