如何在单个 Inno Setup 安装程序中添加 x86 和 x64 VC++ 2019 Redistributables?

How to add x86 and x64 VC++ 2019 Redistributables in single Inno Setup installer?

我正在尝试添加两种架构 [x32 和 x64] VC++ 2019 (v14.26.28720.03) 可在单个设置中重新分发。我编译成功,但在运行时我在 ExtractTemporaryFile('#VcInstall');

中遇到异常
;Version: v14.26.28720.03
[Setup]
#if arch == "x32"
  #define VcInstall "VC_redist.x86.exe"
#else
  #define VcInstall "VC_redist.x64.exe"
#endif

[Files]
Source: ".\Redist\{#VcInstall}"; DestDir: {tmp}; Flags: dontcopy

[Run]
Filename: "{tmp}\{#VcInstall}"; Parameters: "/q /norestart"; \
    Check: VC2019RedistNeedsInstall; Flags: waituntilterminated; \
    StatusMsg: "Installing VC++ 2019 redistributables..." 
[Code]
function VC2019RedistNeedsInstall: Boolean;
var 
  Version: String;
begin
  if (RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\VisualStudio.0\VC\Runtimes\x64', 'Version', Version)) then
  begin
    Log('VC Redist Version check : found ' + Version);
    Result := (CompareStr(Version, 'v14.26.28720.03')<0);
  end
    else 
  begin
    Result := True;
  end;
  if (Result) then
  begin
    ExtractTemporaryFile('#VcInstall');
  end;
end;

我在运行时遇到异常 ExtractTemporaryFile('#VcInstall');

Internal error: #VcInstall was not found


我的解决方案基于@Martin 的回答:

[Code]
function VC2019RedistNeedsInstall(Arch: string): Boolean;
var 
  Version: String;
begin
  Result := True;
  if Arch = 'x64' then
  begin
    if RegKeyExists( HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{CB4A0FDE-1126-4AE2-97C6-A243692C3D95}') then
    begin
      Log('VC Redist Version check : found ');
      Result := False;
    end;
  end;
  if Arch = 'x32' then
  begin
    if RegKeyExists( HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{2F69FB2B-2C48-491C-B249-22C1BDCE1117}') then
    begin
      Log('VC Redist Version check : found ');
      Result := False;
    end;
  end;
end;

您的 VcInstall 代码是预处理器代码。它在编译时执行,因此它考虑了您的开发机器架构。你所做的不是想要的。

而是使用 Is64BitInstallMode or IsWin64(阅读他们的文档以根据您的需要选择正确的)。并且您需要无条件地将两个版本的可再发行组件包含到您的安装程序中。

[Files]
Source: ".\Redist\VC_redist.x86.exe"; DestDir: {tmp}
Source: ".\Redist\VC_redist.x64.exe"; DestDir: {tmp}

[Run]
Filename: "{tmp}\VC_redist.x86.exe"; Parameters: "/q /norestart"; \
    Check: Is64BitInstallMode and VC2019RedistNeedsInstall('x86'); \
    Flags: waituntilterminated; \
    StatusMsg: "Installing VC++ 2019 redistributables..."
Filename: "{tmp}\VC_redist.x64.exe"; Parameters: "/q /norestart"; \
    Check: (not Is64BitInstallMode) and VC2019RedistNeedsInstall('x64'); \
    Flags: waituntilterminated; \
    StatusMsg: "Installing VC++ 2019 redistributables..."
[Code]
function VC2019RedistNeedsInstall(Arch: string): Boolean;
var 
  Version: String;
begin
  if RegQueryStringValue(
       HKEY_LOCAL_MACHINE,
       'SOFTWARE\Microsoft\VisualStudio.0\VC\Runtimes\' + Arch,
       'Version', Version) then
  begin
    Log('VC Redist Version check : found ' + Version);
    Result := (CompareStr(Version, 'v14.26.28720.03')<0);
  end;
end;

(未测试)