如何使用带有错误日志记录的 electron wix creator 解决 msi 包创建中的错误?

问题描述 投票:0回答:0

我正在尝试从具有错误记录功能的 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)
}

然后我尝试使用以下步骤创建 msi 包:

  • 第一步:
    go get github.com/akavel/rsrc
  • 第二步:
    rsrc -ico .\abc.ico
  • 第三步:
    $Env:GOOS="windows"; go build -ldflags "-H windowsgui" -o ABC.exe
  • 第四步:
    npm install electron-wix-msi@latest
  • 第五步:
    npm install node-gyp@latest --save-dev
  • 第 6 步:
    npm install child_process@latest --save-dev
  • 第七步:
    npm install [email protected] --save-dev
  • 第八步:
    npm 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();

然后我运行命令

node .\msi_creator.js

但是我收到以下错误:

Created the .wxs template file.
Defining the MSIErrorLog DLL function...
TypeError: msiCreator.defineMsiErrorLogFunction is not a function

如何解决这个问题?如何存储与应用程序崩溃相关的错误日志?

感谢和问候, 手册

node.js go npm electron windows-installer
© www.soinside.com 2019 - 2024. All rights reserved.