WiX:定义一个可能不存在的File组件

发布于 2024-08-09 22:27:16 字数 105 浏览 2 评论 0原文

我需要定义一个在某些情况下可能不存在的 Wix 文件组件。有什么办法可以做到这一点吗? Wix 中的条件元素似乎都在安装时起作用,我需要一些可以在编译时检测文件是否存在并相应地构建安装程序的东西。

I need to define a Wix file component that may not exist in certain circumstances. Is there any way to do this? Condition elements in Wix all seem to work at install time, and I need something that'll detect at compile time if a file is present and build the installer accordingly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

身边 2024-08-16 22:27:16

看来你需要检查一下 wix 预处理器。查看有关该主题的 wix 文档:
wix 预处理器

例如,假设您有一个名为 APPTYPE 的环境变量。如果其值设置为“Full”,则 MyApp_Full.exe 将由 wix 编译器(蜡烛)包含并处理。

<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>

还有更多!变量、定义、条件。查看该文档页面。

It seems you need to check out the wix preprocessor. Check out wix documentation on the topic:
wix preprocessor

for example, suppose you have an environment variable called APPTYPE. If its value is set to 'Full', then MyApp_Full.exe will be included and processed by the wix compiler (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>

There is more! Variables, defines, conditionals. Check out that doc page.

你列表最软的妹 2024-08-16 22:27:16

正如 iwo 所说,预处理器变量是你的朋友!然而,来自 iwo 的示例可能(并且将会)违反组件规则,因为该组件不是“稳定”的。更好地调节整个组件(或组件组)...

<?if $(var.releasetype)=full ?>
  <ComponentRef Id="Somefile.dll" />
<?elseif  $(var.releasetype)=enterprise ?>
  <ComponentGroupRef Id="SomethingElse" />
<?endif?>

然后将 ComponentComponentGroup 包含在单独的 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 来调用 candlelight 目标,为各种不同的构建和产品定义不同的变量,片段和预处理器变量的有效使用为项目之间或同一项目的不同版本之间的代码重用提供了很好的机会。

在您的情况下,要检查文件是否存在...那么您只需使用内部函数来定义或重新定义稍后传递给 WiX 的变量。例如:

<if test="${not file::exists('something.dll')}">
    <property name="releasetype" value="blahblahblah" />
</if>

As iwo said, preprocessor variables are your friend! However the example from iwo can (and will) violate component rules, as the component isn't 'stable'. Better to condition an entire component (or component group)...

<?if $(var.releasetype)=full ?>
  <ComponentRef Id="Somefile.dll" />
<?elseif  $(var.releasetype)=enterprise ?>
  <ComponentGroupRef Id="SomethingElse" />
<?endif?>

And then include the Component and ComponentGroups in separate Fragment tags so that they will only be compiled when referenced :)

<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>

Personally I use nant to call candle and light targets, defining different variables for various different builds and products, effective use of fragments and preprocessor variables provides a great opportunity for code re-use between projects, or various releases of the same project.

In your case, to check if a file exists... then you'd just use the internal functions to define, or redefine a variable that is later passed to WiX. e.g.:

<if test="${not file::exists('something.dll')}">
    <property name="releasetype" value="blahblahblah" />
</if>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文