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

◇◆丶佛笑我妖孽 提交于 2020-07-05 08:18:30

问题


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:


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.



来源:https://stackoverflow.com/questions/1006574/how-to-persist-app-config-through-clickonce-updates-using-configurationmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!