更新安装:如何保存app.config?
我有一个大问题:
我有一个旧的应用程序 App1.0.exe。此应用程序有一个名为 App1.0.exe.config(应用程序配置)的文件。现在我制作了版本 2.0,新版本现在 Appconfig 中有不同的 Appsettings。我的问题是:进行更新安装时如何保存旧的 Appconfig?
此尝试解决问题失败了:
- 使用 BeforeInstall 事件读出旧配置,保存到上下文参数并在 Afterinstall 事件中写入新配置。 - BeforeInstall 读出新配置(旧配置被删除)。 - 不要复制新的 Appconfig,而是复制具有不同名称的文件,例如包含新 appconfig 的 AppConfigUpdate.config。在安装后事件中,我使用 File.Move() 保存旧配置。现在有:
-Appconfig.exe.config_Original
-AppconfigUpdate.config
比我读出 .config_Original 并将参数写入 AppConfigUpdate.config 并将其重命名为 Appconfig.exe.config
我的问题是 msi 中有一个标准操作在执行名为“RemoveExistingProducts”的自定义操作后执行。因此,现在当我调试安装程序时,我可以在自定义操作的末尾看到旧配置 .config_original 和新配置 .config 以及旧配置中的正确参数。但在我的自定义操作之后,安装删除了 .config,只保留了 .config_original。
我认为RemoveExistingProducts删除了更新包中未提供的所有文件。但我无法提供 .config,因为它覆盖了原始配置并且所有参数都丢失了。
我现在正在解决这个问题超过三天,我真的需要你的帮助。我已经没有办法解决这个问题了,也许你们中的任何人都遇到过类似的问题?
抱歉我的英语不好。 此致
I have a huge problem:
I have an old application App1.0.exe. With this Application there is a file called App1.0.exe.config (the App config). Now i made the Version 2.0, with the new Version now there are different Appsettings in the Appconfig. My question is: How i can save the old Appconfig when make an Update Installation?
This try's to solve the problem have failed:
-Read out the old config with BeforeInstall event, save to the context parameters and write in the new config in an Afterinstall event. - The BeforeInstall read out the new config (the old one is deleted).
-Don't copy the new Appconfig but Copy a File with an different name e.g. AppConfigUpdate.config who include the new appconfig. In an afterinstall Event i save the old Config with an File.Move(). Now whe have:
-Appconfig.exe.config_Original
-AppconfigUpdate.config
Than i read out the .config_Original and write the parameter in the AppConfigUpdate.config and rename this to Appconfig.exe.config
My problem is that there is a standard action in msi that execute after execute my custom actions called: RemoveExistingProducts. So now when i Debugg the installer i can see at the end of my customaction there is the old configuration .config_original and the new configuration .config with the right params from the old configuration. But after my custom action the installation delete the the .config and only the .config_original is remaining.
I think that the RemoveExistingProducts delete all files that were not delivered with the update package. But i can't deliver the .config because than it's overwrite the original config and all params are lost.
I'm now working over 3 day's on this problem and i really need your help. I run out of ideas how to solve this problem, maby anyone of you had some similar problem?
Sorry for my bad english.
best regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正确的方法是使用两个自定义操作来备份和恢复旧的配置文件。备份自定义操作将在删除现有产品操作之前执行。恢复自定义操作将在 InstallFiles 之后执行。一些简单的脚本自定义操作就可以完成这项工作。
有关自定义操作的更多详细信息,请参阅:
http://msdn .microsoft.com/en-us/library/aa368066(VS.85).aspx
不幸的是,Visual Studio 安装程序没有良好的调度支持自定义操作。您将必须使用其他免费或商业 msi 创作工具。
The correct approach would be to use two custom actions to back-up and restore your old config file. The back-up custom action would be executed before RemoveExistingProducts action. The restore custom action would be executed after InstallFiles. Some simple script custom action would do the job.
For more details on custom actions please see:
http://msdn.microsoft.com/en-us/library/aa368066(VS.85).aspx
Unfortunately Visual Studio setup doesn't have a good scheduling support custom actions. You will have to use another free or commercial msi authoring tool.
也许可以解决安装程序的行为?
可以让您的应用程序在启动时测试配置是否为“版本 1”格式,而不是在安装期间重写配置。如果是这样,它会在此时执行更新。
这里有关于更新 app.config 的(旧的,但有效的)详细信息: http://geekswithblogs.net/ akraus1/articles/64871.aspx 。
Perhaps it's possible to work around the behaviour of the installer?
Rather than re-write the configuration during installation, what could work is for your application to test on startup whether the configuration is of the "Version 1" format. If so, it performs the update at that point.
There's (old, but valid) details on updating app.config here: http://geekswithblogs.net/akraus1/articles/64871.aspx .