Wix 刻录不允许删除文件

Wix burn doesn't allow to remove file

我正在创建一个 bootsrapper,我想删除在安装过程中创建的链接。所以我写了以下步骤:

<Chain>
  ...
  <ExePackage Id="removelnk" Cache="no" SourceFile="run.bat" InstallCommand="del &quot;C:\Users\Public\Desktop\Parity UI.lnk&quot;" />
</Chain>

其中 run.bat 只是 %*,它允许 运行 描述的任意代码 here

然而,它不起作用:

[19EC:0E2C][2018-06-16T18:32:27]i301: Applying execute package: removelnk, action: Install, path: C:\ProgramData\Package Cache08BB75347CD8C40187E5F3C0A969ED73A98D51\run.bat, arguments: '"C:\ProgramData\Package Cache08BB75347CD8C40187E5F3C0A969ED73A98D51\run.bat" del "C:\Users\Public\Desktop\Parity UI.lnk"'
[19EC:0E2C][2018-06-16T18:32:27]e000: Error 0x80070001: Process returned error: 0x1
[19EC:0E2C][2018-06-16T18:32:27]e000: Error 0x80070001: Failed to execute EXE package.
[0AE4:2B94][2018-06-16T18:32:27]e000: Error 0x80070001: Failed to configure per-machine EXE package.
[0AE4:2B94][2018-06-16T18:32:27]i319: Applied execute package: removelnk, result: 0x80070001, restart: None
[0AE4:2B94][2018-06-16T18:32:27]e000: Error 0x80070001: Failed to execute EXE package.

如果我从我的 cmd 登录执行此命令,那么它会按预期工作。它甚至可以在没有管理员权限的情况下工作。

这是怎么回事?

刻录不支持批处理文件。所有修改机器的东西都应该打包完成。

创建转换:您可以使用 transform 修改任何 MSI 文件 - a转换的最常见用途是删除此类快捷方式。您应该能够在引导程序中指定的命令行上应用该转换——尽管我从未在 WiX 引导程序中尝试过。

转换 "little database fragments" 应用于原始 MSI。它会更改内存中的 MSI 文件,您几乎可以随心所欲地进行更改。您可以使用 . Commercial tools - such as Advanced Installer - can also be used of course. In fact they have a nice little video showing the process(朝向底部)创建转换。

此处对转换(除其他外)有很长的解释:How to make better use of MSI files.


应用转换:您在安装期间通过Transforms property应用转换。

命令行快速示例:

msiexec.exe /I "My.msi" /QN /L*V "C:\My.log" TRANSFORMS="C:31.mst;C:\My.mst"

快速参数说明:

/I = run installation sequence
/QN = run completely silently
/L*V "C:\My.log"= verbose logging
TRANSFORMS="C:31.mst;C:\My.mst" = Apply transforms 1031.mst and My.mst.

Burn Bundle 详细信息:我没有尝试在 Burn bundle 中应用转换(所以我应该有不回答的感觉), 但 MsiPackage element is what you need I believe. I found this rather complicated sample of a Burn bundle source file - perhaps it is worth a look? It seems the magic is in the MsiProperty child element for the MsiPackage element.


更新:

Burn Hello-World 样式示例:终于 运行 对 Windows 进行了快速测试计算机(在 Linux 一台上)。 这是通过 Burn 应用转换的方法(最小样本,只是为了展示基础知识,而不是假装是好的标记)。

Just inlining the warning: I hear some rumors that the application of the transform in this way might not work in all cases - such as repair. Please test thoroughly. It worked for my test. Also test upgrade scenarios (major upgrade for example).

这会将转换 ShortcutDesktop.mst 应用于原始 MSI ShortcutDesktop.msi:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:bal="http://schemas.microsoft.com/wix/BalExtension">

    <!-- Maybe generate yourself an Upgrade-GUID here: https://www.guidgenerator.com/ -->

    <Bundle Name="MyCoolTestApp" Version="1.0.0.0" Manufacturer="Someone"
            UpgradeCode="PUT-GUID-HERE">        

    <BootstrapperApplicationRef Id="WixStandardBootstrapperApplication.RtfLicense" />

        <Chain>
            <MsiPackage SourceFile="ShortcutDesktop.msi">
                <MsiProperty Name="TRANSFORMS" Value="ShortcutDesktop.mst" />
            </MsiPackage>
        </Chain>

    </Bundle>

</Wix>

要构建上面的 Burn 包 BurnTest.wxs

set SetupName=BurnTest

candle.exe %SetupName%.wxs -ext WixBalExtension >> %SetupName%.log
light.exe %SetupName%.wixobj -ext WixBalExtension >> %SetupName%.log

还有一个 link 到 github 上更好的 Burn 示例: