How to persist app.config through ClickOnce update

2020-07-10 10:53发布

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条回答
beautiful°
2楼-- · 2020-07-10 11:06

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.

查看更多
登录 后发表回答