Wix在卸载时启动应用程序

时间:2013-06-03 11:38:54

标签: wix

使用Wix为我正在处理的应用程序创建Windows Installer安装程序时遇到了一个奇怪的问题。

基本上,当应用程序卸载时,它似乎是在最终完成卸载之前启动应用程序的可执行文件。我不知道为什么这样做,因为我是Wix的新手。

这是完整的Wix代码,我是从here获得的。

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define Product_Name="Orbit Invoice System"?>
  <?define Product_Manufacturer="Orbit"?>
  <?define Product_Name_Short="OIS"?>
  <?define Product_Manufacturer_Short="Orbit"?>
  <?define MainExeID="MainExeID"?>
  <!--<?define Product_Version=!(bind.fileVersion.$(var.MainExeID))?>-->
  <?define Product_Version=!(bind.assemblyVersion.$(var.MainExeID))?>
  <?define SetupResourcesDir=$(var.SolutionDir)\icons\?>

  <Product Id="*" Name="$(var.Product_Name)" Version="$(var.Product_Version)" Manufacturer="$(var.Product_Manufacturer)"
           Language="1033"
           UpgradeCode="F9A23E67-669B-40E5-9995-D8425D08F35F">

    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <!--Check for .Net Framework 3.5 SP 1-->
    <PropertyRef Id='NETFRAMEWORK40FULL'/>
    <Condition Message="This application requires .NET Framework 4.0. Please install the .NET Framework then run this installer again.">
      <![CDATA[Installed OR NETFRAMEWORK40FULL]]>
    </Condition>

    <MajorUpgrade DowngradeErrorMessage="A newer version of $(var.Product_Name) is already installed."
                  Schedule="afterInstallValidate"
                  />

    <MediaTemplate EmbedCab="yes" />

    <Feature Id="ProductFeature" Title="$(var.Product_Name) Setup" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>

    <!--Icon must be 16x16-->
    <Icon Id="AddRemoveProgramsIcon" SourceFile="$(var.SetupResourcesDir)libra.ico"/>
    <Property Id="ARPPRODUCTICON" Value="AddRemoveProgramsIcon" />
    <!--<Property Id="ARPHELPLINK" Value="" />-->

    <InstallExecuteSequence>
      <Custom Action="CleanUpUserData" After="InstallInitialize">Installed AND NOT UPGRADINGPRODUCTCODE AND NOT REINSTALL</Custom>
      <!--<Custom Action="LaunchApplication" Before="InstallFinalize" >UPGRADINGPRODUCTCODE OR REINSTALL OR NOT Installed</Custom>-->
    </InstallExecuteSequence>

  </Product>

  <Fragment>
    <CustomAction Id="CleanUpUserData" FileKey="$(var.MainExeID)" ExeCommand="cleanUpUserData" Execute="immediate" Impersonate="yes" Return="ignore"/>
    <!--<CustomAction Id="LaunchApplication" FileKey="$(var.MainExeID)" ExeCommand="mustBeSomethingOrTheUpdateWillFailWithError2753" Execute="commit" Impersonate="yes" Return="asyncNoWait"/>-->
  </Fragment>

  <!--Directory general structure-->
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <!--Program Files-->
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="$(var.Product_Name)" />
      </Directory>
      <!--Startup Programs Menu-->
      <Directory Id="ProgramMenuFolder" Name="Programs">
        <Directory Id="ProgramMenuDir" Name="$(var.Product_Manufacturer)">
          <Component Id="ProgramMenuDir" Guid="*" >
            <Shortcut Id="UninstallProduct"
                      Name="Uninstall $(var.Product_Name)"
                      Target="[SystemFolder]msiexec.exe"
                      Arguments="/x [ProductCode]"
                      Description="Uninstalls $(var.Product_Name)" />
            <RemoveFolder Id='ProgramMenuDir' On='uninstall' />
            <RegistryValue Root='HKCU' Key='Software\$(var.Product_Manufacturer_Short)\$(var.Product_Name_Short)' Type='string' Value='' KeyPath='yes' />
          </Component>
        </Directory>
      </Directory>
      <!--Desktop-->
      <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>
  </Fragment>

  <!--Directory file structure-->
  <Fragment>
    <DirectoryRef Id="INSTALLFOLDER">
      <Component Id="MainExecutable" Guid="*">
        <File Id="$(var.MainExeID)" Name="$(var.Product_Name).exe" Source="$(var.Invoice.TargetPath)" DiskId="1" KeyPath="yes" Vital="yes"
              Assembly=".net" AssemblyApplication="$(var.MainExeID)">
          <Shortcut Id="MainExeDesktop" Directory="DesktopFolder" Name="$(var.Product_Name)" WorkingDirectory="INSTALLFOLDER"
                    Icon="MainExeIcon.exe"
                    Description="Launches the $(var.Product_Name) application" Advertise="yes" >
            <Icon Id="MainExeIcon.exe" SourceFile="$(var.Invoice.TargetPath)"/>
          </Shortcut>
          <Shortcut Id="MainExeProgramMenu" Directory="ProgramMenuDir" Name="$(var.Product_Name)" WorkingDirectory="INSTALLFOLDER"
                    Icon="MainExeIcon.exe"
                    Description="Launches the $(var.Product_Name) application" Advertise="yes" />
          <Shortcut Id="CleanUpLocalFiles" Directory="ProgramMenuDir" Name="CleanUp the Local Files" Arguments="cleanUpUserData" WorkingDirectory="INSTALLFOLDER"
                    Icon="MainExeIcon.exe"
                    Description="Cleanup all the downloaded files of the $(var.Product_Name) for the current user" Advertise="yes"/>
        </File>
      </Component>
      <Component Id="MainExecutableConfig" Guid="BDFC3501-CB6A-4C75-A4AE-05C0F7FE2DC2">
        <File Id="MainExeConfig" Name="$(var.Product_Name).exe.config" Source="$(var.Invoice.TargetPath).config" DiskId="1" KeyPath="yes" Vital="yes" />
        <File Id="InvoiceConfig" Name="InvoiceConfiguration.dll" Source="$(var.Invoice.TargetDir)\InvoiceConfiguration.dll" DiskId="1" Vital="yes" />
        <File Id="DocumentFormatOpenXml" Name="DocumentFormat.OpenXml.dll" Source="$(var.Invoice.TargetDir)\DocumentFormat.OpenXml.dll" DiskId="1" Vital="yes" />
        <File Id="SalesInvoiceTemplate" Name="SalesInvoiceTemplate.docx" Source="$(var.Invoice.TargetDir)\SalesInvoiceTemplate.docx" DiskId="1" Vital="yes" />
      </Component>
    </DirectoryRef>
  </Fragment>

  <!--Components groups-->
  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <ComponentRef Id="MainExecutable" />
      <!--<ComponentRef Id="Dlls" />
      <ComponentRef Id="LetterTemplates"/>-->
      <ComponentRef Id="MainExecutableConfig" />
      <ComponentRef Id="ProgramMenuDir" />
    </ComponentGroup>
  </Fragment>
</Wix>

有什么想法吗?

2 个答案:

答案 0 :(得分:4)

CleanUpUserData 自定义操作运行$(var.MainExeID)应用程序。

<CustomAction Id="CleanUpUserData" FileKey="$(var.MainExeID)" ExeCommand="cleanUpUserData" Execute="immediate" Impersonate="yes" Return="ignore"/>

以下条件(已安装且未升级,并且不重新安装)表示如果已安装安装程序且未升级或重新安装,则将运行自定义操作。因此它将在RepairUninstall中运行(两者都符合此条件)。因此,您的应用程序正在卸载中运行。

<Custom Action="CleanUpUserData" After="InstallInitialize">Installed AND NOT UPGRADINGPRODUCTCODE AND NOT REINSTALL</Custom>

详细了解安装和卸载条件here

答案 1 :(得分:1)

在查看@Vinoth给出的答案后,我已将'CleanUpUserData'自定义操作更改为:

<Custom Action="CleanUpUserData" After="InstallInitialize">INSTALLED OR UPGRADINGPRODUCTCODE OR REINSTALL</Custom>

现在这已经解决了这个问题。