简体   繁体   English

WIX-根据预处理程序变量更改APPLICATIONFOLDER

[英]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. 我有一个WIX MSI项目,该项目用于我们产品的不同口味,因此我有各种声明要根据产品的口味/类型做事,并且知道一切似乎都按预期进行。 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. 但是,现在已经决定需要将其中一种口味安装在其他位置(实际上是安装到其他公司的安装文件夹中-由于我们的应用程序不是GAC的),但是我现在正在尝试一些“有趣”的尝试实现这一点。

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. 就目前而言,这很好-它会安装到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; 但是我有一个称为FLAVOR的PreProcessor变量,可以为1或2。如果为1,那么我想安装到上述结构中; BUT if it's 2 I'd like to install into Program Files\\SecondCompany\\SecondProduct 但如果是2,我想安装到Program Files \\ SecondCompany \\ SecondProduct

Basically if it's 2 - then we actually install into another company's install location. 如果基本上是2,那么我们实际上将安装到另一家公司的安装位置。

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. 尽管当我运行安装程序时这些方法都可以正常编译(btw Wix 3.6),但是它会抱怨诸如“无法访问网络位置XXXXXXXX”的错误,其中XXXXXX是APPLICATIONFOLDER中的值。

I've now reached ( doesn't take much ) my limit of my Wix skills, so hoping someone on here can shed some light ? 我现在已经达到(不需要很多)我的Wix技能极限,所以希望有人在这里可以阐明一些想法?

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. 使用<CustomAction><SetDirectory>将目录设置为新路径时,必须将目录设置为完整路径 ,而不仅仅是单个片段。

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. 由于您要在APPLICATIONFOLDER目录中设置完整路径,因此无需更改COMPANYFOLDER目录。

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)">
           ....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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