如何使用ConfigurationManager通过ClickOnce更新来持久保存app.config?

时间:2023-02-12 01:51:48

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...

这个问题完全描述了我的问题,除了我在app.config中使用ConfigurationManager的自定义配置部分,因此那里提供的解决方案不适用...

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.

基本上,我的问题是当ClickOnce更新应用程序时,它会使用新的app.config安装到不同的目录中,从而删除所做的任何更改。我的应用程序使用app.config来保存应用程序设置,所以这非常糟糕...合并的更新将非常好(类似于在另一个问题中实现的),但几乎任何自动化的东西都会很好。

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

或者我应该只为app.config文件使用设置位置而不是尝试使用默认位置?

2 个解决方案

#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.

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

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.

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

Perhaps this approach could work for you as well.

也许这种方法对你也有用。

Edited to add references:

编辑添加引用:

Googling for ApplicationDeployment should also help.

谷歌搜索ApplicationDeployment也应该有所帮助。

#2


If you can, use Settings.settings (found under Properties in your project) to store your customer configuration.

如果可以,请使用Settings.settings(位于项目中的“属性”下)来存储客户配置。

ClickOnce will automatically merge your user settings and you won't have to worry about anything. Check out something like this for more instructions: http://www.dotnetperls.com/settings-visual-studio

ClickOnce将自动合并您的用户设置,您不必担心任何事情。查看类似的内容以获取更多说明:http://www.dotnetperls.com/settings-visual-studio

#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.

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

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.

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

Perhaps this approach could work for you as well.

也许这种方法对你也有用。

Edited to add references:

编辑添加引用:

Googling for ApplicationDeployment should also help.

谷歌搜索ApplicationDeployment也应该有所帮助。

#2


If you can, use Settings.settings (found under Properties in your project) to store your customer configuration.

如果可以,请使用Settings.settings(位于项目中的“属性”下)来存储客户配置。

ClickOnce will automatically merge your user settings and you won't have to worry about anything. Check out something like this for more instructions: http://www.dotnetperls.com/settings-visual-studio

ClickOnce将自动合并您的用户设置,您不必担心任何事情。查看类似的内容以获取更多说明:http://www.dotnetperls.com/settings-visual-studio