man*_*oos 5 go node.js npm electron electron-wix-msi
我正在尝试从 golang 程序创建一个具有错误日志功能的 msi 包。因此,我将能够检索 golang 应用程序崩溃日志。
以下 Golang 代码保存到main.go,预计会因1\0除法相关错误而崩溃。
package main
import "fmt"
func main() {
// intentionally cause a divide-by-zero error
x := 0
y := 1 / x
fmt.Println(y)
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用以下步骤创建 msi 包:
go get github.com/akavel/rsrcrsrc -ico .\abc.ico$Env:GOOS="windows"; go build -ldflags "-H windowsgui" -o ABC.exenpm install electron-wix-msi@latestnpm install node-gyp@latest --save-devnpm install child_process@latest --save-devnpm install fs@0.0.1-security --save-devnpm i exe-icon-extractor@latest --save-dev然后我创建了一个 javascript 文件名msi_creator.js来生成 msi 包。JavaScript代码如下:
const { MSICreator } = require("electron-wix-msi");
const path = require("path");
const { execSync } = require("child_process");
async function start() {
try {
// Step 2: Instantiate the MSICreator
const msiCreator = new MSICreator({
appDirectory: path.resolve("."),
description: "ABC",
exe: "ABC.exe",
name: "ABC",
manufacturer: "FFFF",
version: "0.1.0",
upgradeCode: "{12343238-1111-2222-3333-123483275556}",
removeExistingProduct: true,
iconPath: "./abc.ico",
outputDirectory: path.resolve("./output/"),
});
// Step 4: Create a .wxs template file
console.log("Creating the .wxs template file...");
await msiCreator.create();
console.log("Created the .wxs template file.");
// Step 5: Define the MSIErrorLog DLL function
console.log("Defining the MSIErrorLog DLL function...");
msiCreator.defineMsiErrorLogFunction(
function MSIErrorLog(hInstall) {
var exePath = session.property('CustomActionData');
var errorLogFile = session.property('MsiErrorLogFile');
try {
var child_process = require('child_process');
child_process.execFile(exePath, {stdio: 'ignore'}, function (error, stdout, stderr) {
if (error) {
var fs = require('fs');
var logFile = fs.createWriteStream(path.join(process.env['TEMP'], 'msi_error.log'), {flags: 'a'});
logFile.write('Error: ' + error.message + '\n');
logFile.end();
}
});
} catch (e) {
var fs = require('fs');
var logFile = fs.createWriteStream(path.join(process.env['TEMP'], 'msi_error.log'), {flags: 'a'});
logFile.write('Error: ' + e.message + '\n');
logFile.end();
}
}
);
console.log("Defined the MSIErrorLog DLL function.");
// Step 6: Compile the template to a .msi file
console.log("Compiling the .wxs template...");
await msiCreator.compile();
console.log("Compiled the .wxs template to an MSI installer.");
} catch (error) {
console.error(error);
}
}
start();
Run Code Online (Sandbox Code Playgroud)
然后我运行命令
node .\msi_creator.js
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误:
Created the .wxs template file.
Defining the MSIErrorLog DLL function...
TypeError: msiCreator.defineMsiErrorLogFunction is not a function
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?如何存储与应用程序崩溃相关的错误日志?
谢谢和问候, 马努
考虑到该electron-wix-msi模块似乎不包含任何defineMsiErrorLogFunction()功能,因此得到“ TypeError: msiCreator.defineMsiErrorLogFunction is not a function”也就不足为奇了。
您可以在.wsx文件中包含一条指令来:
ABC.exe并记录任何错误<InstallExecuteSequence>
<Custom Action="RunCollectLogs" After="InstallFinalize" />
...
</InstallExecuteSequence>
<Product>
<Binary Id="CollectLogs" SourceFile="collect_logs.js" />
<CustomAction Id="RunCollectLogs" BinaryKey="CollectLogs" ExeCommand="node collect_logs.js" Execute="deferred" />
...
</Product>
Run Code Online (Sandbox Code Playgroud)
正如此处提到的,自定义操作必须是延迟的自定义操作才能在之后运行InstallFiles。
和collect_logs.js:
const fs = require("fs");
const path = require("path");
const { exec } = require("child_process");
const logPath = path.join(process.env["TEMP"], "msi_error.log");
exec("ABC.exe", (error, stdout, stderr) => {
if (error) {
const logFile = fs.createWriteStream(logPath, { flags: "a" });
logFile.write("Error: " + error.message + "\n");
logFile.end();
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
169 次 |
| 最近记录: |