WiX Search and Replace on a configuration file

回眸只為那壹抹淺笑 提交于 2019-12-23 16:53:21

问题


I'm trying to make an install using WiX and I need to modify a configuration file (not XML or INI) with entries that a customized WiX dialog.

Is there a good way to do this? Do I need to make a VB script custom action, perhaps?

Below is the relevant bits of the wxs file:

   <Directory Id="TARGETDIR" Name="SourceDir">
     <Directory Id="ProgramFilesFolder">
         <Directory Id="INSTALLLOCATION" Name="MyApp">
             <Component Id="ap_cfg" KeyPath="yes" Guid="...">
                 <File Id="CONFIGFILE" Source="myConfig.cfg" />
              </Component>
         </Directory>
      </Directory>
   </Directory>

回答1:


There is no build in Search & Replace construct in Wix, you will need to write a custom action.
I suggest that instead of using VBScript you will use DTF which will enable you to write the custom action in .net and debug it under Visual Studio.




回答2:


So you want to install a config file, by modify it dynamically during installation?

You're better off writing a custom action in native/unmanaged code like C++ that reads the various MSI properties and writes them out to your config file. Don't install the file with a keypath at any rate, otherwise as soon as it's modified it won't match the original hash and will be repaired. Better to just write out the "default" config from the binary table or something and then modify it, that way windows installer doesn't care what you do with it.

I wouldn't advise using managed code for your custom actions either, use C++ and you'll save yourself a lot of headaches down the road. There are a few very good examples in the WiX toolset source to get you started.

Finally, before you even think about using VBScript go and read why VBScript (and Jscript) MSI CustomActions suck.



来源:https://stackoverflow.com/questions/1186415/wix-search-and-replace-on-a-configuration-file

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