9

我正在编写托管自定义操作。我正在使用 Windows Installer Xml 中的 DTF 框架将托管 dll 包装到可用的 CA dll 中。CA 做了它应该做的事情,但我仍然遇到错误处理问题:

Dim record As New Record(1)

' Field 0 intentionally left blank
' Field 1 contains error number
record(1) = 27533
session.Message(InstallMessage.Error, record)

上面的代码在 MSI 日志中生成以下文本:

MSI (c) (C4 ! C6) [13:15:08:749]:产品:TestMSI -- 错误 27533。区分大小写的密码不匹配。

错误编号是指包含在 MSI 中的错误表中的代码。上面显示的消息是正确的。

我的问题是:为什么 Windows Installer 不创建一个对话框来通知用户错误?

4

3 回答 3

16

MSI 可以做到这一点,但您需要为 messageType 参数添加一些额外的值。

例如。

Record record = new Record();
record.FormatString = string.Format("Something has gone wrong!");

session.Message(
    InstallMessage.Error | (InstallMessage) ( MessageBoxIcon.Error ) |
    (InstallMessage) MessageBoxButtons.OK,
    record );

有关更多详细信息,请参阅wix-users 邮件列表中的此线程

于 2009-04-23T04:29:40.077 回答
2

根据Wix:Nick Ramirez 的Windows Installer XML 开发人员指南,我遇到了同样的问题,当从UI 控件调用自定义操作时,日志和消息方法不起作用。

于 2012-01-11T16:00:28.193 回答
-3

如果您希望显示包含该消息的对话框,您必须自己完成。

下面是一些我用来在运行 SQL 的托管自定义操作中进行错误处理的代码。如果安装使用完整的 UI 运行,它会显示一个消息框。它在 c# 中,但希望你能明白。

    private void _handleSqlException(SqlException ex)
    {
        StringBuilder errorMessage = new StringBuilder();
        errorMessage.Append("A SQL error has occurred.");
        for (int i = 0; i < ex.Errors.Count; i++)
        {
            errorMessage.Append("Index #" + i + "\n" +
                "Message: " + ex.Errors[i].Message + "\n" +
                "LineNumber: " + ex.Errors[i].LineNumber + "\n" +
                "Source: " + ex.Errors[i].Source + "\n" +
                "Procedure: " + ex.Errors[i].Procedure + "\n");
        }
        session.Log(errorMessage);
        if (session["UILevel"] == "5")
        {
            MessageBox.Show(errorMessage);
        }
    }
于 2009-03-17T15:49:16.990 回答