首页 > 解决方案 > 使用 Inno Setup 启动 .NET Core 安装程序失败,结果代码为 2

问题描述

我正在尝试使用 Inno Setup 构建安装程序。我需要为 .NET Core 框架设置先决条件安装。到目前为止,我能够检测到 .NET Core 的存在。但是我在执行安装时遇到了困难。

这是我到目前为止的代码:

[Files]
Source: "\\shared\path\dotnet-runtime-3.1.10-win-x64.exe"; DestDir: "{tmp}"; \
  Flags: deleteafterinstall; BeforeInstall: InstallFramework; \
  Check: FrameworkIsNotInstalled

[Code]
var 
  CancelWithoutPrompt: boolean;
  InstallValue: Cardinal;

function InitializeSetup(): Boolean;
begin
  CancelWithoutPrompt := false;
  result := true;
end;

procedure CancelButtonClick(CurPageID: Integer; var Cancel, Confirm: Boolean);
begin
  if CurPageID=wpInstalling then
    Confirm := not CancelWithoutPrompt;
end;
             
function FrameworkIsNotInstalled: Boolean;
begin
  Result := not RegQueryDWordValue(HKEY_LOCAL_MACHINE, 
    'SOFTWARE\WOW6432Node\dotnet\Setup\InstalledVersions\x64\sharedfx\Microsoft.NETCore.App', 
    '3.1.10', InstallValue) or (InstallValue <> 1)
end;

procedure InstallFramework;
var
  StatusText: string;
  ResultCode: Integer;
begin
  StatusText := WizardForm.StatusLabel.Caption;
  WizardForm.StatusLabel.Caption := 'Installing .net core framework...';
  WizardForm.ProgressGauge.Style := npbstMarquee;
  try
    if not Exec(ExpandConstant('{tmp}\dotnet-runtime-3.1.10-win-x64.exe'), '/q /norestart', '', SW_SHOW, ewWaitUntilTerminated, ResultCode) then     
    begin
      // you can interact with the user that the installation failed
      MsgBox('.NET Core installation failed with code: ' + IntToStr(ResultCode) + '.',
        mbError, MB_OK);
      CancelWithoutPrompt := true;
      WizardForm.Close;       
    end;
  finally
    WizardForm.StatusLabel.Caption := StatusText;
    WizardForm.ProgressGauge.Style := npbstNormal;
  end;
end;

我从安装中得到结果代码 2 响应,任何人都可以告诉我代码 2 错误是什么?还是我可以通过任何方式提取有关错误信息的更多详细信息?我尝试了空参数并尝试在互联网上搜索 Code 2 错误信息,但仍然没有运气。我曾尝试使用 Shellexec 并且都返回相同的结果

直接使用 .net exe 安装在本地运行良好

任何帮助或信息将不胜感激=)

标签: .net-coreinno-setuppascalscript

解决方案


您正在尝试dotnet-runtime-3.1.10-win-x64.exe在实际将其“安装”到之前运行{tmp}

BeforeInstall: InstallFramework

您必须使用AfterInstall参数

AfterInstall: InstallFramework

推荐阅读