仅在安装或卸载时执行自定义操作

Enc*_*ine 2 windows-installer custom-action wix wix3.10

我正在使用WiX 3.10制作安装程序.我的原始任务是将Postgres文件复制到目标系统,初始化集群,注册服务,启动它并在安装时恢复数据库,以及反向停止服务,将其从系统中删除,并清除集群数据.我编写了两个bat文件,并添加了自定义操作来执行它们以及各个地方描述的一些条件,但它们都没有工作.我已尝试使用和不使用CDATA,已安装,已安装和其他一些变体,但它始终执行这两个操作.

这是我正在尝试的wix文件.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*" Name="Hatred_6" Language="1033" Version="1.0.0.0" Manufacturer="Satan" UpgradeCode="d9602b10-8428-4031-8c82-99288b21377f">
        <Package InstallerVersion="405" Compressed="yes" InstallScope="perMachine"  InstallPrivileges="elevated"/>

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes" />

        <CustomAction Id="AAction" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" Return="check"
                      ExeCommand="cmd.exe /c &quot;a.bat&quot;">NOT Installed</CustomAction>

        <CustomAction Id="BAction" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" Return="check"
                      ExeCommand="cmd.exe /c &quot;b.bat&quot;">Installed</CustomAction>

        <InstallExecuteSequence>
            <Custom Action="BAction" After="InstallFiles" />
            <Custom Action="AAction" After="InstallFiles" />
        </InstallExecuteSequence>

        <Feature Id="ProductFeature" Title="Hatred_6" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="Hatred_6" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <Component Id="CalcComponent" Guid="515C0606-FD73-4B5D-ACF4-481123092A3E">
                <File Id="CalcFile" KeyPath="yes" Source="calc.exe" />
            </Component>
            <Component Id="AComponent" Guid="515e3aa0-e5a0-4cd1-aaa5-ebf25a679a24">
                <File Id="AFile" KeyPath="yes" Source="a.bat" />
            </Component>
            <Component Id="BComponent" Guid="85f7627e-fc39-4f78-a870-221d2d08375d">
                <File Id="BFile" KeyPath="yes" Source="b.bat" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>
Run Code Online (Sandbox Code Playgroud)

bat文件包含dir> a.txt和dir> b.txt,所以我可以看到它们是否实际执行过.这有点令人沮丧,我误解了什么吗?

Ant*_*min 7

条件应放​​在Custom元素内,而不是CustomAction.此外,卸载期间没有InstallFiles操作.请改用RemoveFiles.

<CustomAction Id="AAction" Directory="INSTALLFOLDER" Execute="deferred" 
              Impersonate="no" Return="check" ExeCommand="cmd.exe /c &quot;a.bat&quot;" />
<CustomAction Id="BAction" Directory="INSTALLFOLDER" Execute="deferred"
              Impersonate="no" Return="check" ExeCommand="cmd.exe /c &quot;b.bat&quot;" />

<InstallExecuteSequence>
    <Custom Action="AAction" After="InstallFiles">NOT Installed</Custom>
    <Custom Action="BAction" Before="RemoveFiles">Installed</Custom>
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)