Wix - install directory depending on a condition

2019-07-29 02:45发布

In my wix source code, I have to look for 2 entries in the registry to get an install directory :

<Property Id="INSTALLDIR_A"> 
 <RegistrySearch Id='RegA' Type='raw' 
   Root='HKLM' Key='Software\Path\To\A' Name='InstallLocation' /> 

 <Property Id="INSTALLDIR_B"> 
 <RegistrySearch Id='RegB' Type='raw' 
   Root='HKLM' Key='Software\Path\To\B' Name='InstallLocation' /> 

My install directory must be either INSTALLDIR_A or INSTALLDIR_B. If I had to look only to 1 entry, I would have implemented it like that :

<Directory Id="TARGETDIR" Name="SourceDir">
  <Directory Id="INSTALLDIR" Name="My path">
    <!-- further code -->
  </Directory>
</Directory>

But I want INSTALLDIR to be either INSTALLDIR_A or INSTALLDIR_B depending on which one is defined. How to achieve this ?

1条回答
淡お忘
2楼-- · 2019-07-29 03:47

There's a custom action SetDirectory (http://wixtoolset.org/documentation/manual/v3/xsd/wix/setdirectory.html) for that. You might try something like using the first value as default and overwriting it if the other one is set:

<Fragment>
  <Directory Id="TARGETDIR" Name="SourceDir">
    <Directory Id="ProgramFilesFolder">
      <Directory Id="INSTALLFOLDER" Name="Software\Path\To\A" />
    </Directory>
  </Directory>

  <SetDirectory Id="INSTALLFOLDER" Value="[INSTALLDIR_B]">INSTALLDIR_B AND NOT INSTALLDIR_A</SetDirectory>
</Fragment>
查看更多
登录 后发表回答