Update and retain web.config file during upgrade in wix installer

时光总嘲笑我的痴心妄想 提交于 2019-12-02 14:13:31

问题


What is the standard way to handle web.config files during major upgrade.I'm aware how the unversioned files are handled during upgrade,the file will not be replaced if the file has been modified by the user.

Is there a way to deal with the scenario where in there are new entries added to config file bundled with the latest installer that needs to be installed,and also retain the existing entries modified by the user during major upgrade in Wix.


回答1:


The simple solution that a lot of my customers have liked is to not put user data in the web.config. Instead we use the AppSettings@file and ConnectionStrings@ConfigSource elements to specify an override file and keep the user data there. What MSI doesn't know about it won't tamper with. Now you don't have to be an MSI component rules wizard.

https://msdn.microsoft.com/en-us/library/ms228154(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource(v=vs.100).aspx




回答2:


I know the question is for Wix, but just wanted to point out how much time commercial tools can save in such scenarios.

For example, using Advanced Installer you can read and load into an MSI property any XML values and then use the XML Files updater to write dynamic content in the files, at install(upgrade) time. (check the videos at the end of each article for a quicker overview)

Disclaimer: I work on the team building Advanced Installer.




回答3:


Set the component to always overwrite and write a custom action to add the needed information to the config file.




回答4:


The only way that seems possible is a custom action to merge the entries in the new file into the existing file, because you want data from the existing a new files. You would also need the upgrade scheduled late (after InstallExecute) so that the upgrade isn't an uninstall of the old product followed by an install of the new product.

If you are doing an upgrade (the WIX_UPGRADE_DETECTED property will be set by a MajorUpgrade element), so update the existing file, otherwise install the new one.

There might be a way to express the updates as an Xml transform, so something in the WiX util:xml tools might help do an update.



来源:https://stackoverflow.com/questions/49126365/update-and-retain-web-config-file-during-upgrade-in-wix-installer

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