根据条件在WiX中设置属性 [英] Set a property in WiX based on a condition
问题描述
这应该很简单,但是几个小时后,我空白了。 ;(
This should be easy, but after several hours I’m coming up blank. ;(
我进行注册表搜索(实际上是两个),因为我需要检查两个先前安装的 ,然后安装新的文件到找到的先前安装的位置。
I do a registry search (actually two), because I need to check for either of two previous installs and then install my new files to the location of the prior install that was found.
- 这些先前安装中只有一个实际上存在
- Only one of these prior installs will actually exist.
然后我需要将新文件安装到找到 PROD#的 InstallLocation。
I then need to install my new files to the 'InstallLocation' of which 'PROD#' was found.
<!— Look for the UnInstall key of the 1st possible product -->
<!— GUID = {E928E024-DEFE-41A7-8469-D338212C4943} -->
<Property Id='PROD1'>
<RegistrySearch Id='PROD_REG1'
Type='raw'
Root='HKLM'
Key='$(var.REGKEY_PROD1)'
Name='InstallLocation' />
</Property>
<!— Look for the UnInstall key of the 2nd possible product -->
<!— GUID = {A40A9018-DB9D-4588-A591-F012600C6300} -->
<Property Id='PROD2'>
<RegistrySearch Id='PROD_REG2'
Type='raw'
Root='HKLM'
Key='$(var.REGKEY_PROD2)'
Name='InstallLocation' />
</Property>
<!-- How do I set INSTALL_HERE Property to whichever ‘InstallLocation’ was found? -->
<!-- Define the directory structure -->
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="INSTALL_HERE">
<Directory Id="MAIN_DIRECTORY" Name="MyProduct"/>
<Directory Id="HELP_DIRECTORY" Name="Help"/>
</Directory>
</Directory>
推荐答案
以下内容将为结果设置属性A和B两个不同的注册表搜索。如果对B的搜索成功,它将用B的值覆盖A的值。
The following will set properties A and B to the result of two different registry searches. If the search for B was successfull, it overrides the value of A with the value of B.
<Property Id="A">
<!-- registry search 1 here -->
</Property>
<Property Id="B">
<!-- registry search 2 here -->
</Property>
<SetProperty Id="A" After="AppSearch" Value="[B]">
B
</SetProperty>
请注意 SetProperty 元素两次使用B的值:一次作为 Value = [B]
覆盖值A,一次作为自定义操作的条件文本。 After = AppSearch
确保在注册表搜索后立即执行自定义操作。
Note how the SetProperty element uses the value of B twice: once as Value="[B]"
to override the value of A, and once as the condition text of the custom action. The After="AppSearch"
ensures that the custom action is executed right after the registry searches.
另请参见< a href = https://stackoverflow.com/questions/1215320/set-wix-property-only-if-certain-condition-is-met/1215855#1215855> Rob Mensching的答案
这篇关于根据条件在WiX中设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!