在MSI中使用[SourceDir]进行WiX自定义操作和刻录

dav*_*_uk 0 wix burn

我们的安装程序使用CustomAction(在InstallExecuteSequence中调用)可选地从安装程序旁边的目录中复制用户配置文件.这使用[SourceDir]来定位源目录.

我们目前有32位和64位版本,它们作为单独的.MSI文件分发.我正在尝试使用Burn构建包含这些.MSI文件的单个.EXE.显然当Burn安装了MSI时,它的[SourceDir]位于其他地方(我看到了C:\ProgramData\Package Cache\...路径),所以这个自定义动作不起作用.

我找到了WixBundleOriginalSource变量,但我的问题是我希望MSI文件能够独立工作并与Burn一起打包.我认为我需要有条件地将变量设置为WixBundleOriginalSource(如果已定义(用户使用Burn .exe))或者如果未定义WixBundleOriginalSource(用户直接安装.MSI)则将SourceDir设置为SourceDir,然后将此变量传递给我的自定义操作.(我知道WixOriginalSource是安装程序的完整路径,而不是它所在的目录 - 我可以在我的自定义操作中处理它.)

这可能吗?如果是这样,请帮我解释一下语法.

更新:

我可能会在自定义操作中处理条件部分,并调用它两次:一次使用[SourceDir](直接使用MSI时有效),正如我现在所做的那样:

在我的产品中

    <CustomAction Id='CopyConfigFiles'
                  FileKey="MyInstallationUtility"
                  ExeCommand="COPYFILES [SourceDir]"
                  Execute="deferred"
                  Impersonate="no"
                  Return="ignore" />
Run Code Online (Sandbox Code Playgroud)

......和一次WixBundleOriginalSource.但是,我找不到办法让WixBundleOriginalSource我自定义动作.使用:

                  ExeCommand="COPYFILES [WixBundleOriginalSource]"
Run Code Online (Sandbox Code Playgroud)

......不起作用.使用:

在我的Burn Bundle中

    <WixVariable Id="ConfigFileLocation" Value="[WixBundleOriginalSource]" />
Run Code Online (Sandbox Code Playgroud)

在我的产品中

                  ExeCommand="COPYFILES [ConfigFileLocation]"
Run Code Online (Sandbox Code Playgroud)

......也行不通.两者都给我一个空字符串作为参数.

dav*_*_uk 6

解决方案是在MSI脚本中定义一个可以通过刻录覆盖的属性,如果刻录没有设置,则使MSI脚本将其设置为[SourceDir].

在MSI脚本中,我们定义属性(将其初始化为我们稍后测试的'unset')以及将其设置为[SourceDir]的自定义操作:

    <Property Id='CONFIGFILELOCATION' Value='unset' />
    <CustomAction Id='MsiConfigLoc' Property='CONFIGFILELOCATION' Value='[SourceDir]' Execute='immediate' />
Run Code Online (Sandbox Code Playgroud)

需要安装程序位置的自定义操作已更新为使用此新属性:

<CustomAction Id='CopyConfigFiles'
              FileKey="MyInstallationUtility"
              ExeCommand="COPYFILES [CONFIGFILELOCATION]"
              Execute="deferred"
              Impersonate="no"
              Return="ignore" />
Run Code Online (Sandbox Code Playgroud)

然后将InstallExecuteSequence扩展为有条件地调用新的自定义操作(在CopyConfigFiles之前) - 仅当刻录EXE尚未设置CONFIGFILELOCATION时:

        <Custom Action='MsiConfigLoc' Before='CopyConfigFiles'>CONFIGFILELOCATION="unset"</Custom>
        <Custom Action='CopyConfigFiles' Before='InstallFinalize'/>
Run Code Online (Sandbox Code Playgroud)

最后,在Burn Bundle中我们将CONFIGFILELOCATION属性设置为[WixBundleOriginalSource]:

        <MsiPackage SourceFile='ProductSetup.msi' DisplayInternalUI='yes'>
            <MsiProperty Name='CONFIGFILELOCATION' Value='[WixBundleOriginalSource]' />
        </MsiPackage>
Run Code Online (Sandbox Code Playgroud)

从WiX 3.9开始,最好使用,[WixBundleOriginalSourceFolder]因为它给出了安装程序可执行文件所在的目录.我在[WixBundleOriginalSource]这里使用(安装程序可执行文件的完整路径)并处理在我的自定义安装代码中删除文件名.