尽管WIX设置失败,但Word Add in安装

时间:2017-04-23 22:40:52

标签: c# wix office-addins

使用WIX工具集v3.10.3.3007创建安装程序以安装MS Word添加。如何确保故障完全回滚?

我正在向WIX对话框序列中注入自定义操作以检查用户输入的值。如果检查失败,我想安装失败。 我有明确触发故障的条件,但即使触发了故障,Add In仍然安装并且仍在运行。故意故障会弹出预期的对话框,说明:

  

..安装向导因错误而提前结束。您的系统尚未修改......

除此之外,我的系统已被修改。以下是我认为你需要看到的内容。我是一个WIX新手,所以我不确定我是否遗漏了相关内容:

安装日志:

...MSI (c) (E8:8C) [18:09:07:125]: Doing action: ActivateCustomAction
MSI (c) (E8:8C) [18:09:07:125]: Note: 1: 2205 2:  3: ActionText 
Action 18:09:07: ActivateCustomAction. 
Action start 18:09:07: ActivateCustomAction.
MSI (c) (E8:30) [18:09:07:127]: Invoking remote custom action. DLL: C:\Users\tekhe\AppData\Local\Temp\MSIC0B9.tmp, Entrypoint: RegisterAddIn
SFXCA: Extracting custom action to temporary directory: C:\Users\tekhe\AppData\Local\Temp\MSIC0B9.tmp-\
SFXCA: Binding to CLR version v4.0.30319
Calling custom action RegisterAddIn!RegisterAddIn.CustomActions.RegisterAddIn
Begin CustomAction1
CustomAction ActivateCustomAction returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)
Action ended 18:09:07: ActivateCustomAction. Return value 3.
MSI (c) (E8:8C) [18:09:07:347]: Doing action: FatalError
MSI (c) (E8:8C) [18:09:07:347]: Note: 1: 2205 2:  3: ActionText 
Action 18:09:07: FatalError. 
Action start 18:09:07: FatalError.
Action 18:09:07: FatalError. Dialog created
Action ended 18:14:08: FatalError. Return value 2.
Action ended 18:14:08: INSTALL. Return value 3.
MSI (c) (E8:8C) [18:14:08:137]: Destroying RemoteAPI object.
MSI (c) (E8:A8) [18:14:08:137]: Custom Action Manager thread ending.
...

自定义操作:

using System;
using Microsoft.Deployment.WindowsInstaller;

namespace RegisterAddIn
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult RegisterAddIn(Session session)
        {
            try
            {
                session.Log("Begin CustomAction1");
                string token = session["ActivationToken"];

                if (token == null)
                {
                    throw new Exception("No token set yet");
                }

                if (token == "fail it")
                {
                    return ActionResult.Failure;
                }

                session.Log("Captured activation token = " + session["ActivationToken"]);
                return ActionResult.Success;
            }
            catch (Exception e)
            {
                session.Log(e.Message);
                return ActionResult.Failure;
            }    
        }
    }
}

Product.wxs的部分。 CustomInstallDir是标准WIX WixUI_InstallDir.wxs标记的副本,添加了自定义操作。

    <Binary Id="RegisterAddIn" SourceFile="$(var.RegisterAddIn.TargetDir)RegisterAddIn.CA.dll" />
    <CustomAction Id="ActivateCustomAction"
              BinaryKey="RegisterAddIn"
              DllEntry="RegisterAddIn"
              Execute="immediate"
              Return="check" />

   <InstallUISequence>
      <Custom Action="ActivateCustomAction" After="ExecuteAction" />
    </InstallUISequence>

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <!--<MediaTemplate/>-->
    <Media Id="1" Cabinet="VTSAddin.cab" EmbedCab="yes"/>
    <Feature Id="ProductFeature" Title="Word Add In" Level="1">
      ...Component Refs elided
    </Feature>
    <UIRef Id="CustomInstallDir" />

CustomInstallDir.wxs部分在TokenPromptDlgVerifyReadyDlg之间注入自定义对话框(InstallDirDlg):

  <Publish Dialog="InstallDirDlg" Control="Next" Event="SpawnDialog" Value="InvalidDirDlg" Order="3"><![CDATA[NOT WIXUI_DONTVALIDATEPATH AND WIXUI_INSTALLDIR_VALID<>"1"]]></Publish>
  <Publish Dialog="InstallDirDlg" Control="Next" Event="NewDialog" Value="TokenPromptDlg" Order="4">WIXUI_DONTVALIDATEPATH OR WIXUI_INSTALLDIR_VALID="1"</Publish>
  <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Property="_BrowseProperty" Value="[WIXUI_INSTALLDIR]" Order="1">1</Publish>
  <Publish Dialog="InstallDirDlg" Control="ChangeFolder" Event="SpawnDialog" Value="BrowseDlg" Order="2">1</Publish>

  <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="TokenPromptDlg" Order="1">NOT Installed</Publish>
  <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="MaintenanceTypeDlg" Order="2">Installed AND NOT PATCH</Publish>
  <Publish Dialog="VerifyReadyDlg" Control="Back" Event="NewDialog" Value="WelcomeDlg" Order="2">Installed AND PATCH</Publish>

  <Publish Dialog="MaintenanceWelcomeDlg" Control="Next" Event="NewDialog" Value="MaintenanceTypeDlg">1</Publish>

自定义对话框xml(TokenPromptDialog.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <UI>
      <Dialog Id="TokenPromptDlg"
              Width="370"
              Height="270"
              Title="Activation">

<!-- Next, Back, Cancel, etc., buttons elided -->

        <Control Id="ActivationTokenLabel"
                 Type="Text" X="10" Y="50" Width="250" Height="18"
                 Text="Enter your validation token" />

        <Control Id="MyTextbox"
           Type="Edit" 
           Property="ActivationToken" 
           X="10" Y="75" Width="250" Height="18" />

      </Dialog>
      <Publish Dialog="TokenPromptDlg"
         Control="Back"
         Event="NewDialog"
         Value="InstallDirDlg" Order="1">1</Publish>

      <Publish Dialog="TokenPromptDlg"
               Control="Next"
               Event="NewDialog"
               Value="VerifyReadyDlg" Order="1">1</Publish>
    </UI>
  </Fragment>
</Wix>

0 个答案:

没有答案
相关问题