Wix Bundle源路径和项目结构

时间:2014-11-07 12:10:11

标签: wix installer bootstrapper

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

第三方应用程序是一个包含大量补充文件的.exe包。

我的问题是,如何将第三方应用程序包含在我的Bundle中?我是否也将所有完整文件(100多个文件)添加为有效负载?

以下代码是我如何设置我的Bundle到目前为止,它正在编译但没有安装,日志说引导程序.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>

2 个答案:

答案 0 :(得分:2)

是的,您必须列出每个有效负载。将它们放在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 to Payload和周围的DirectoryRef到PayloadGroup的音译。

答案 1 :(得分:0)

同意为具有许多文件的安装程序手动生成有效负载是一件痛苦的事! 这是一个小的PowerShell脚本,用于生成给定路径的有效负载xml。它将生成guid以用作id,递归文件夹并重现文件夹结构。

if($args.Length -eq 0) {
    Write-Host "Error: No argument. Supply path to payload folder as script argument."
    Exit 1
}
$path = $args[0]
foreach($file in Get-ChildItem -Name $path -File -Recurse)
{
    Write-Host ("<Payload Id=`"" + ([guid]::NewGuid()) + "`" SourceFile=`"" + (Join-Path -Path $path -ChildPath $file) + "`" Name=`"" + $file + "`" />")
}