我需要定义一个在某些情况下可能不存在的 Wix 文件组件。有没有办法做到这一点?Wix 中的条件元素似乎都在安装时工作,我需要在编译时检测文件是否存在并相应地构建安装程序的东西。
2131 次
2 回答
2
看来您需要查看 wix 预处理器。查看有关该主题的 wix 文档: wix 预处理器
例如,假设您有一个名为 APPTYPE 的环境变量。如果它的值设置为“Full”,那么 MyApp_Full.exe 将被 wix 编译器 (candle) 包含并处理。
<Component Id='MyComponent1' Guid='fff60f72-5553-4e6b-9bf0-ad62ab9a90b1'>
<?if $(env.APPTYPE) = Full?>
<File Name='MyApp_Full.exe' DiskId='1' Source='..\MyApp_Full.exe' Vital='yes' />
<?endif?>
...
</Component>
还有更多!变量、定义、条件。查看该文档页面。
于 2009-11-05T22:20:16.827 回答
1
正如 iwo 所说,预处理器变量是你的朋友!然而,来自 iwo 的示例可能(并且将会)违反组件规则,因为组件不是“稳定的”。更好地调节整个组件(或组件组)......
<?if $(var.releasetype)=full ?>
<ComponentRef Id="Somefile.dll" />
<?elseif $(var.releasetype)=enterprise ?>
<ComponentGroupRef Id="SomethingElse" />
<?endif?>
然后将Component
and包含ComponentGroup
在单独的Fragment
标签中,这样它们只会在引用时被编译:)
<Fragment>
<Component Id="Somefile.dll" Guid="*">
<File Id="Somefile.dll" KeyPath="yes" Source="SourceDir\Somefile.dll" />
</Component>
</Fragment>
<Fragment>
<ComponentGroup Id="SomethingElse">
<ComponentRef Id="Somefile.dll" />
<Component Id="AnotherFile.dll>
<File Id="AnotherFile.dll" KeyPath="yes" Source="SourceDir\AnotherFile.dll" />
</Component>
</ComponentGroup>
</Fragment>
就我个人而言,我使用nant来调用candle
和light
定位,为各种不同的构建和产品定义不同的变量,有效地使用片段和预处理器变量为项目之间的代码重用或同一项目的不同版本提供了很好的机会。
在您的情况下,要检查文件是否存在......然后您只需使用内部函数来定义或重新定义稍后传递给 WiX 的变量。例如:
<if test="${not file::exists('something.dll')}">
<property name="releasetype" value="blahblahblah" />
</if>
于 2009-11-06T00:24:01.747 回答