如何使用ConfigurationManager通过ClickOnce更新保留app.config? [英] How to persist app.config through ClickOnce updates using ConfigurationManager?

查看:139
本文介绍了如何使用ConfigurationManager通过ClickOnce更新保留app.config?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题描述了我的问题完全一样,只是我在app.configConfigurationManager中使用了自定义配置部分,因此此处介绍的解决方案不适用...

基本上,我的问题是,ClickOnce更新应用程序时,它将与新的app.config一起安装到其他目​​录中,从而擦除所做的任何更改.我的应用程序使用app.config来保留应用程序设置,因此这非常糟糕……合并的更新将非常出色(类似于在另一个问题中实现的更新),但是此时几乎所有自动化的方法都将是好的./p>

还是我应该只为我的app.config文件使用一个设置的位置,而不是尝试使用默认位置?

解决方案

ClickOnce应该在两次更新之间维护用户设置,但是由于未知的原因,我一次或两次失败(并且结果很差).我没有尝试过自定义配置设置,但是我对ClickOnce不会覆盖设置的能力失去了信心.

我计划使用的方法是手动处理ClickOnce更新,而不是允许应用程序.检查更新并提示用户安装.我也有几个不接受更新的用户,要从中恢复很痛苦.通过手动处理更新,我希望能够在更新之前将用户设置读入内存,然后在更新完成后将其写回.有一个应该用于此目的的ApplicationUpdated事件.

也许这种方法也可以为您服务.

编辑后添加了引用:

搜索ApplicationDeployment也应有所帮助.

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?

解决方案

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.

这篇关于如何使用ConfigurationManager通过ClickOnce更新保留app.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆