检查Inno Setup中是否安装了.NET 5.0

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

我有以下 .iss 脚本来编译我正在开发的使用 .NET 5.0 的游戏启动器。目前,它每次都会尝试从安装程序安装 .NET 5.0,而不是先检查是否需要。我找到了大量资源来告诉您如何针对 .NET Framework 执行此操作,但几乎没有找到针对 .NET 5.0(.NET Core 的更新版本)的资源。在尝试安装之前如何检查 .NET 5.0 是否已安装?

我也知道 5.0 即将结束,但我使用的是 Visual Studio 2019,它与 6.0 不兼容,并且不希望使用任何变通办法来让 2019 与它合作。

#define AppName "LowPoly Games Launcher"
#define AppEXEName "LPG Launcher.exe"

[Setup]
AppName={#AppName}

[Files]
Source: "..\bin\Release\net5.0-windows\*"; DestDir: "{app}"; \
    Flags: ignoreversion recursesubdirs;
Source: "Resources\windowsdesktop-runtime-5.0.17-win-x64.exe"; \
    DestDir: "{app}"; Flags: ignoreversion deleteafterinstall

[Run]
Filename: "{app}\{#AppEXEName}"; \
    Description: "{cm:LaunchProgram, {#StringChange(AppName, '&', '&&')}}"; \
    Flags: nowait postinstall
Filename: "{app}\windowsdesktop-runtime-5.0.17-win-x64.exe"; \
    Parameters: "/q/passive"; Flags: waituntilterminated; \
    StatusMsg: Microsoft .NET Framework 5.0 is being installed. Please wait...
.net-core inno-setup
1个回答
6
投票

基于:

你可以这样做:

[Code]

function IsDotNetInstalled(DotNetName: string): Boolean;
var
  Cmd, Args: string;
  FileName: string;
  Output: AnsiString;
  Command: string;
  ResultCode: Integer;
begin
  FileName := ExpandConstant('{tmp}\dotnet.txt');
  Cmd := ExpandConstant('{cmd}');
  Command := 'dotnet --list-runtimes';
  Args := '/C ' + Command + ' > "' + FileName + '" 2>&1';
  if Exec(Cmd, Args, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and
     (ResultCode = 0) then
  begin
    if LoadStringFromFile(FileName, Output) then
    begin
      if Pos(DotNetName, Output) > 0 then
      begin
        Log('"' + DotNetName + '" found in output of "' + Command + '"');
        Result := True;
      end
        else
      begin
        Log('"' + DotNetName + '" not found in output of "' + Command + '"');
        Result := False;
      end;
    end
      else
    begin
      Log('Failed to read output of "' + Command + '"');
    end;
  end
    else
  begin
    Log('Failed to execute "' + Command + '"');
    Result := False;
  end;
  DeleteFile(FileName);
end;

它的用法如下:

if IsDotNetInstalled('Microsoft.NETCore.App 5.0.') then // ...

请注意,上述内容适用于 .NET。对于旧版 .NET Framework(5.0 之前的版本),请使用

IsDotNetInstalled
支持功能

© www.soinside.com 2019 - 2024. All rights reserved.