2016-09-10 65 views
0

我正在使用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> 

BAT文件包含DIR> A.TXT和dir> b.txt所以我可以看到,如果他们真的执行。 这有点令人沮丧,我误解了什么?

+0

我建议使用详细日志而不是'dir> a.txt'来确定自定义动作是否执行。 –

+0

无论如何,我需要两个bat文件产生副作用,并且我没有找到详细日志中的任何内容来解释如何评估操作条件。 – Encarmine

回答

6

条件应放在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> 
+0

这些情况在升级过程中仍会运行。 “已安装”是指正在安装的{Product GUID}产品。通过重大升级,产品GUID不同,但升级GUID匹配,因此我们知道哪些产品是升级产品。我会将这两个条件修改为'NOT WIX_UPGRADE_DETECTED AND NOT Installed']和'NOT UPGRADINGPRODUCTCODE AND REMOVE〜=“ALL”'以使这些操作仅在首次安装时运行**并完成卸载。 –

+0

@BrianSutherland,你是对的,但经验表明,在重大升级期间应该停止服务,所以对于作者而言,原始条件更好。 –

+0

@SutarminAnton我犯的错误有点尴尬,你的建议有帮助。至于确切的条件,我需要 - 有一些好的cheatsheet在其他SO答案像这样http://stackoverflow.com/questions/320921/how-to-add-a-wix-custom-action-that-happens-only-上卸载,通过微星 – Encarmine

相关问题