Wix 仅在安装或卸载时执行自定义操作
我正在用WIX3.10制作安装程序。我最初的任务是将Postgres文件复制到目标系统,初始化集群,注册服务,启动它并在安装时恢复数据库,在反向停止服务中,将其从系统中删除,并清除集群数据。我编写了两个bat文件,并添加了自定义操作来执行它们,以及在不同地方描述的一些条件,但它们都不起作用。我尝试过使用和不使用CDATA、Installed、Installed和其他一些变体,但它总是执行这两种操作 这是我正在试验的wix文件Wix 仅在安装或卸载时执行自定义操作,wix,windows-installer,custom-action,wix3.10,Wix,Windows Installer,Custom Action,Wix3.10,我正在用WIX3.10制作安装程序。我最初的任务是将Postgres文件复制到目标系统,初始化集群,注册服务,启动它并在安装时恢复数据库,在反向停止服务中,将其从系统中删除,并清除集群数据。我编写了两个bat文件,并添加了自定义操作来执行它们,以及在不同地方描述的一些条件,但它们都不起作用。我尝试过使用和不使用CDATA、Installed、Installed和其他一些变体,但它总是执行这两种操作 这是我正在试验的wix文件 <?xml version="1.0" encoding="UT
<?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 "a.bat"">NOT Installed</CustomAction>
<CustomAction Id="BAction" Directory="INSTALLFOLDER" Execute="deferred" Impersonate="no" Return="check"
ExeCommand="cmd.exe /c "b.bat"">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>
未安装
安装
bat文件包含dir>a.txt和dir>b.txt,因此我可以查看它们是否实际执行。
这有点令人沮丧,我误解了什么吗?条件应该放在
Custom
元素中,而不是CustomAction
中。此外,在卸载过程中,您没有安装文件的操作。改用删除文件
<CustomAction Id="AAction" Directory="INSTALLFOLDER" Execute="deferred"
Impersonate="no" Return="check" ExeCommand="cmd.exe /c "a.bat"" />
<CustomAction Id="BAction" Directory="INSTALLFOLDER" Execute="deferred"
Impersonate="no" Return="check" ExeCommand="cmd.exe /c "b.bat"" />
<InstallExecuteSequence>
<Custom Action="AAction" After="InstallFiles">NOT Installed</Custom>
<Custom Action="BAction" Before="RemoveFiles">Installed</Custom>
</InstallExecuteSequence>
未安装
安装
我建议使用详细日志而不是dir>a.txt
来确定是否执行自定义操作。无论如何,我都需要两个bat文件来产生副作用,而且我在详细日志中找不到任何可以解释操作条件如何评估的内容。升级期间,这些条件仍将运行。“已安装”是指正在安装的{Product GUID}产品。对于主要升级,产品GUID不同,但升级GUID匹配,因此我们知道这是哪个产品的升级。我会将这两个条件修改为NOT WIX\u UPGRADE\u DETECTED AND NOT Installed)
和NOT UPGRADINGPRODUCTCODE并删除~=“ALL”
,以使这些操作仅在首次安装和完成卸载时运行。@BrianSutherland,你是对的,但经验表明,在主要升级期间,服务应该停止,“所以为了作者的目的,原始条件更好。”萨塔米南顿我犯的错误有点尴尬,你的建议帮助了我。至于确切的条件,我需要-有一些很好的备忘表上的其他所以这样的答案