Wix Bundle源码路径和项目结构

2023-12-29

我正在尝试创建一个引导程序安装程序,它将安装我的应用程序以及运行我的应用程序所需的第三方应用程序。

第三方应用程序是一个 .exe 包,其中包含许多补充文件。

我的问题是,如何将第三方应用程序包含到我的捆绑包中?我是否也必须添加所有补充文件(100 多个文件)作为有效负载?

下面的代码是我到目前为止设置捆绑包的方式,它正在编译但未安装,日志显示引导程序 .exe 找不到我的 .msi (我的应用程序)或 .exe (第三方应用程序)

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    <Bundle Name="My_app"
            Version="1.0.0.0"
            Manufacturer="untitled"
            UpgradeCode="4d2de235-2286-4b06-8cfa-3f6ff3174244">

        <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

        <Chain>
            <MsiPackage
                Id="MyApp_msi"
                SourceFile ="MyApp\MyApp.msi"
                Vital ="yes"/>
            <PackageGroupRef Id="thirdParty_package" />
        </Chain>
    </Bundle>

    <Fragment>
        <PackageGroup Id="thirdParty_package">
            <ExePackage
                SourceFile="thirdParty\Setup.exe"
                InstallCommand="/q /ACTION=Install"
                RepairCommand="/q ACTION=Repair /hideconsole"
                UninstallCommand="/q ACTION=Uninstall /hideconsole"/>
        </PackageGroup>
    </Fragment>
</Wix>

是的,您必须列出每个有效负载。将它们放在 PayloadGroup 中很方便。

有很多方法可以生成 PayloadGroup。一种方法是使用/滥用热量来收获目录。这与为安装项目获取目录的方式相同。

作为一个例子,我们来打包 WiX 的 bin 目录。

  <ExePackage Id="MyPackageId" SourceFile="$(env.WiX)bin/dark.exe" Compressed="yes">
    <PayloadGroupRef Id="MyPayloadGroupId"/>
  </ExePackage>

如果您使用 MSBuild(包括通过 Visual Studio),您可以通过在项目文件中添加如下内容来配置收获:

  <ItemGroup>
    <HarvestDirectory Include="$(WIX)/bin">
      <ComponentGroupName>MyPayloadGroupId</ComponentGroupName>
      <PreprocessorVariable>var.MyPayloadSourceDirectory</PreprocessorVariable>
      <Transforms>FilesToPayloads.xsl</Transforms>
      <SuppressRegistry>true</SuppressRegistry>
      <!-- Hide from VS Solution Explorer -->
      <InProject>false</InProject>
    </HarvestDirectory>
  </ItemGroup>

当构建运行时,它将输出 .wsx(在 obj 中)文件夹添加到构建中。 (你不需要看到它。)

请注意,它使用预处理器变量来给出源文件的实际位置。要传递该值,请在项目属性中定义它。或者,作为 .wixproj 中的 XML:

<DefineConstants>Debug;MyPayloadSourceDirectory=C:/Program Files (x86)/WiX Toolset v3.8/bin</DefineConstants>

最后,热量将应用于其正常收获输出的 XSL 转换 (FilesToPayloads.xsl):

<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
  xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <xsl:template match="/">
    <Wix>
      <Fragment>
        <xsl:apply-templates select="*" />
      </Fragment>
    </Wix>
  </xsl:template>

  <xsl:template match="//wix:DirectoryRef">
    <PayloadGroup>
      <xsl:attribute name="Id">
        <xsl:value-of select="/wix:Wix/wix:Fragment/wix:ComponentGroup/@Id"/>
      </xsl:attribute>
      <xsl:apply-templates select="*" />
    </PayloadGroup>
  </xsl:template>

  <xsl:template match="//wix:File">
    <Payload>
      <xsl:attribute name="SourceFile">
        <xsl:value-of select="@Source"/>
      </xsl:attribute>
    </Payload>
  </xsl:template>

</xsl:stylesheet>

这是从 File 到 Payload 以及周围的 DirectoryRef 到 PayloadGroup 的相当简单的音译。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Wix Bundle源码路径和项目结构 的相关文章

随机推荐