我有一个使用CAQuietExec的自定义操作,在某些情况下失败 - 唯一的错误消息出现在日志文件中,这对开发人员来说是非常好的,对最终用户无用。我的目标是在回滚安装之前捕获失败的操作并预设标准错误消息。Wix CustomAction dll
要做到这一点,基于我的研究,我决定我需要编写自己的自定义动作DLL,所以我开始关注this tutorial。在这个阶段,我的dll只记录一条测试消息并尝试将错误消息传回对话屏幕。但是,当我编译并运行msi时,根本没有任何反应 - 没有记录,也没有任何错误消息。看看Orca中的msi,它对我来说看起来不错 - 但正如你可以在下面看到的那样,测试dll应该会导致安装在实际运行时立即中止,而不会立即中止。
所以我的问题:我是否会以最好的方式向用户提供反馈?如果是这样,任何想法为什么我的自定义操作没有运行?
感谢
CustomAction.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
using System.Collections.ObjectModel;
using System.Management.Automation;
namespace MyCustomActions
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
session.Log("Begin CustomAction1");
DisplayMSIError(session, "A test message");
return ActionResult.Failure;
}
static void DisplayMSIError(Session session, String msg)
{
var r = new Record();
r.SetString(0, msg);
session.Message(InstallMessage.Error, r);
}
}
}
Product.wxs
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="MyPackage" Language="1033" Version="0.0.0.1" Manufacturer="Acme" UpgradeCode="GUID">
<Package InstallerVersion="300" Compressed="yes" InstallScope="perMachine" />
<Binary Id="MyCustomActions.CA.dll" src="MyCustomActions\MyCustomActions.CA.dll" />
<CustomAction Id="MyCustomActionsTest"
Return="check"
Execute="immediate"
BinaryKey="MyCustomActions.CA.dll"
DllEntry="CustomAction1" />
<InstallExecuteSequence>
<Custom Action="MyCustomActionsTest" After="LaunchConditions" />
...
</InstallExecuteSequence>
</Product>
</Wix>
我想,也许你只是需要多一点理解的方式失速作品。其中一个重要思想是你遇到的一个问题:InstallUISequence先运行,然后执行序列,所以你的CA在标准的UI对话框之后。 session.message没有错误告诉用户错误。 – PhilDW 2014-10-06 17:10:29