在Wix中设置组件的条件

God*_*ent 3 installer windows-installer wix

在我的Wix中,我以这种方式包含了大量文件:

<Component Id="mycomponent" Guid="*" Feature="Core" >
  <Condition>$(var.Include) = 1</Condition>
  <File Id="mycomponent.file" KeyPath="yes" 
        Source="$(var.BinDir)\mycomponent.file" />
</Component>
Run Code Online (Sandbox Code Playgroud)

所以我可以传入一个不同的var.Include值来为不同的环境生成包.

虽然生成的包看起来确实有效,但是我注意到即使我将它设置为不包含这些组件,包的大小也总是很大.看起来WiX总是包含构建msi的所有组件,并且只有在使用var.Include = 0构建软件包时才选择不安装这些组件...

这是正常行为吗?

Chr*_*ter 6

condition元素用于确定组件是否已安装,而不是它是否包含在构建中.另外,请确保不要混淆条件语句和预处理程序变量/语句中使用的Windows Installer属性.两个不同的野兽.


Rin*_*Tom 5

您可以通过使用某些文件压缩/解压缩软件(例如7zip)打开MSI输出文件来进行确认,然后在打开的MSI文件中打开package.cab文件。并检查您的ID是否为“ mycomponent”之类的文件。

我希望这是期望的,因为它取决于变量,并且甚至可以从install命令调用将其设置为install属性。

更新:您可以使用Preprocessor语句像下面那样修改WIX,以便可以从生成的msi中排除这些可选组件。

    <?if $(env.MySku) = Enterprise ?>
       <Component Id="mycomponent" Guid="*" Feature="Core">
          <Condition>$(var.Include) = 1</Condition>
          <File Id="mycomponent.file" KeyPath="yes" Source="$(var.BinDir)\mycomponent.file" />      
       </Component>
    <?endif ?>
Run Code Online (Sandbox Code Playgroud)