简体   繁体   中英

WIX - Changing APPLICATIONFOLDER based on Preprocessor Variable

I have a WIX MSI project, that is used for different flavours of our product and so I have various statements to do things based on the product flavour/type and up to know everything seems to be working as expected. But it has now been decided that one of the flavours, needs to be installed in a different location ( actually into another companies install folder - due to our app not being GAC'd ), but I'm now having some "fun" trying to implement this.

I have a directory structure, similar to :

<Directory Id="TARGETDIR" Name="SourceDir">
   <Directory Id="ProgramFilesFolder">
      <Directory Id="COMPANYFOLDER" Name="FirstCompany">
         <Directory Id="APPLICATIONFOLDER" Name="FirstProduct"  >

and as it stands that's fine - it will install into Program Files\\FirstCompany\\FirstProduct.

BUT I have a PreProcessor Variable called FLAVOUR that can be either 1 or 2. If it's 1 then I'd like to install into the structure as above; BUT if it's 2 I'd like to install into Program Files\\SecondCompany\\SecondProduct

Basically if it's 2 - then we actually install into another company's install location.

I have tried all sorts of things to accomplish this such as :

<?if $(var.FLAVOUR)=1?>
    <SetDirectory Id="COMPANYFOLDER" Value="FirstCompany" Sequence="execute"/>
    <SetDirectory Id="APPLICATIONFOLDER" Value="FirstProduct" Sequence="execute"/>
<?else?>
    <SetDirectory Id="COMPANYFOLDER" Value="SecondCompany" Sequence="execute"/>
    <SetDirectory Id="APPLICATIONFOLDER" Value="SecondProduct" Sequence="execute"/>
<?endif?

This was done in the same fragment as where the directory structure was set-up - but this didn't work.

Also tried :

    <CustomAction Id="SetCompanyDirToFirst"
                  Directory="COMPANYFOLDER"
                  Value="FirstCompany" />

    <InstallExecuteSequence>
       <Custom Action="SetCompanyDirToFirst" Before="InstallFiles">$(var.FLAVOUR)=1</Custom>
       ....
    </InstallExecuteSequence>

Although these methods compile ok ( btw Wix 3.6 ) when I run the installer it complains with errors such as "Could not access network location XXXXXXXX" where XXXXXX is the value in APPLICATIONFOLDER.

I've now reached ( doesn't take much ) my limit of my Wix skills, so hoping someone on here can shed some light ?

Cheers,

Chris.

When using either <CustomAction> or <SetDirectory> to set a directory to a new path, you must set the directory to the full path , not just the single fragment.

For example:

<?if $(var.FLAVOUR) = 1 ?>
  <SetDirectory Id="APPLICATIONFOLDER" Value="[ProgramFilesFolder]FirstCompany\FirstProduct" Sequence="execute" />
<?else?>
  <SetDirectory Id="APPLICATIONFOLDER" Value="[ProgramFilesFolder]SecondCompany\SecondProduct" Sequence="execute" />
<?endif?>

Since you're setting the full path on the APPLICATIONFOLDER directory, you don't need to change the COMPANYFOLDER directory.

However, If you're using the preprocessor this way, you don't really need to use a custom action at all, you can do everything at build time:

<?if $(var.FLAVOUR) = 1 ?>
  <?define CompanyFolderName = "FirstCompany" ?>
  <?define ProductFolderName = "FirstProduct" ?>
<?else?>
  <?define CompanyFolderName = "SecondCompany" ?>
  <?define ProductFolderName = "SecondProduct" ?>
<?endif?>

<Directory Id="TARGETDIR" Name="SourceDir">
   <Directory Id="ProgramFilesFolder">
      <Directory Id="COMPANYFOLDER" Name="$(var.CompanyFolderName)">
         <Directory Id="APPLICATIONFOLDER" Name="$(var.ProductFolderName)">
           ....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM