對於該文檔,請查找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, 我已檢查記錄不爲空,但它仍然在此行上失敗。任何想法? – tronda 2010-02-03 12:46:45
您是否在MSI中運行腳本?如果是這樣,那麼檢查MSI日誌,通過運行'msiexec/i MYMSI.msi/l * v msilog.txt'可以生成該日誌。日誌存儲在msilog.txt中。我懷疑你可能會丟失decimalToHexString函數。我剛剛在上面添加了。 – Cheeso 2010-02-03 12:57:09
感謝Cheeso發佈上面非常有用的答案!應該注意的是,應該在MSI文件中明確引用入口函數(這裏是MyCustomActionInJavascript)。使用WiX時,這意味着將JScriptCall屬性設置爲入口點函數的名稱。這可能看起來微不足道,但我浪費了幾個小時... – YitzikC 2012-03-14 12:25:20