问题
I have a wix installer that will install an XML file and then modify it. Installation works great. Today, I needed to add a couple of nodes to this XML file. So I modified the original file and then added some additional instructions to wix to assign these items values.
Well, I get an error every time saying that it cannot find the node. I look and see what file it has in the directory and it still has the older file that did not have the node. How can I tell it to replace the XML file first and then modify it? I don't want to use "CreateElement" because I don't know how to not create an element if it exists already (haven't tried it, so maybe it'd work). Besides, I want my XML file to be the definition of the configuration.
Here's a sample of my XML:
<Component Id="MyProgExeConfigComponent" Guid="*">
<File
Id="MyProgExeConfig"
Name="MyProg.exe.config"
DiskId="1"
Source="../Published/MyProg/MyProg.exe.config"
PatchWholeFile="yes"
KeyPath="yes"/>
<util:XmlFile
Id="MyProgExeConfigUser"
Action="setValue"
Permanent="yes"
File="[INSTALLLOCATION]\MyProg.exe.config"
ElementPath="/configuration/appSettings/add[\[]@key='UserName'[\]]"
Name="value"
Value="[USER]"/>
<util:XmlFile
Id="MyProgExeConfigPassword"
Action="setValue"
Permanent="yes"
File="[INSTALLLOCATION]\MyProg.exe.config"
ElementPath="/configuration/appSettings/add[\[]@key='Password'[\]]"
Name="value"
Value="[PASSWORD]" />
Any ideas?
回答1:
Windows Installer is probably not overwriting the file because you have INSTALLMODE=omus and the XML's create and modification dates are different.
Is the XML file the key file of it's own component? If so, try using the File@DefaultVersion attribute to trick Windows Installer into thinking the new file has a version # ( we call this 'Version Lying" when googling ) and therefore trumps the non-versioned file. Your file will be overwritten and then your XML updates can be applied from there.
回答2:
Here are some further options: Forcing an upgrade of a file that is modified during its initial installation. Personally I like the companion file approach best.
来源:https://stackoverflow.com/questions/3603409/how-do-i-force-wix-to-update-a-file-before-manipulating-it-on-an-upgrade