【问题标题】:How to debug an MSI Custom Action that is implemented in Javascript?如何调试在 Javascript 中实现的 MSI 自定义操作?
【发布时间】:2012-03-14 20:25:20
【问题描述】:

我很难弄清楚我的 Javascript 自定义操作失败的原因。

我以为我在 WIX.chm 文件中看到了一个关于调试的主题;现在我找不到它。

第一季度
是否有关于如何调试 Javascript 或 VBScript 自定义操作的文档?

第二季度
有没有办法从自定义操作向 MSI 日志发出一些东西?


附录:
Some people think script is the wrong tool for writing CAs
我不同意。我认为Javascript is a very good tool for the job

【问题讨论】:

    标签: wix windows-installer custom-action


    【解决方案1】:

    对于文档,请查找 Session.Message

    要从 Javascript 自定义操作将消息发送到 MSI 日志,请遵循以下样板代码:

    //
    // CustomActions.js 
    // 
    // Template for WIX Custom Actions written in Javascript.
    // 
    // 
    // Mon, 23 Nov 2009  10:54
    // 
    // ===================================================================
    
    
    // http://msdn.microsoft.com/en-us/library/sfw6660x(VS.85).aspx
    var Buttons = {
            OkOnly           : 0,
            OkCancel         : 1,
            AbortRetryIgnore : 2,
            YesNoCancel      : 3
    };
    
    var Icons = {
            Critical         : 16,
            Question         : 32,
            Exclamation      : 48,
            Information      : 64
    };
    
    var MsgKind = {
            Error            : 0x01000000,
            Warning          : 0x02000000,
            User             : 0x03000000,
            Log              : 0x04000000
    };
    
    // http://msdn.microsoft.com/en-us/library/aa371254(VS.85).aspx
    var MsiActionStatus = {
            None             : 0,
            Ok               : 1, // success
            Cancel           : 2,
            Abort            : 3,
            Retry            : 4, // aka suspend?
            Ignore           : 5  // skip remaining actions; this is not an error.
    };
    
    
    function MyCustomActionInJavascript() {
        try {
            LogMessage("Hello from MyCustomActionInJavascript");
            // ...do work here...
            LogMessage("Goodbye from MyCustomActionInJavascript");
        }
        catch (exc1) {
            Session.Property("CA_EXCEPTION") = exc1.message ;
            LogException(exc1);
            return MsiActionStatus.Abort;
        }
        return MsiActionStatus.Ok;
    }
    
    // Pop a message box.  also spool a message into the MSI log, if it is enabled. 
    function LogException(exc) {
        var record = Session.Installer.CreateRecord(0);
        record.StringData(0) = "CustomAction: Exception: 0x" + decimalToHexString(exc.number) + " : " + exc.message;
        Session.Message(MsgKind.Error + Icons.Critical + Buttons.btnOkOnly, record);
    }
    
    
    // spool an informational message into the MSI log, if it is enabled. 
    function LogMessage(msg) {
        var record = Session.Installer.CreateRecord(0);
        record.StringData(0) = "CustomAction:: " + msg;
        Session.Message(MsgKind.Log, record);
    }
    
    
    // popup a msgbox
    function AlertUser(msg) {
        var record = Session.Installer.CreateRecord(0);
        record.StringData(0) = msg;
        Session.Message(MsgKind.User + Icons.Information + Buttons.btnOkOnly, record);
    }
    
    // Format a number as hex.  Quantities over 7ffffff will be displayed properly.
    function decimalToHexString(number) {
        if (number < 0)
            number = 0xFFFFFFFF + number + 1;
        return number.toString(16).toUpperCase();
    }
    

    【讨论】:

    • 我在 LogException 方法上遇到异常 - 更具体地说是 record.StringData(0) 行。它显示: Microsoft JScript 运行时错误:对象预期第 134 行,第 3 列,我检查了记录不为空,但它仍然在这一行失败。有什么想法吗?
    • 您是否在 MSI 中运行脚本?如果是这样,请检查 MSI 日志,您可以通过运行 msiexec /i MYMSI.msi /l*v msilog.txt 生成该日志。日志存储在 msilog.txt 中。我怀疑您可能缺少 decimalToHexString 函数。我刚刚在上面添加了。
    • 感谢 Cheeso 在上面发布了非常有用的答案!应该注意的是,应在 MSI 文件中明确引用入口点函数(此处为 MyCustomActionInJavascript)。使用 WiX 时,这意味着将 JScriptCall 属性设置为入口点函数的名称。这可能看起来微不足道,但我浪费了几个小时......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 1970-01-01
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    相关资源
    最近更新 更多