【问题标题】:Check if .NET 5.0 is installed in Inno Setup检查 Inno Setup 中是否安装了 .NET 5.0
【发布时间】:2022-10-22 22:14:42
【问题描述】:

我有以下 .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】:

    基于:

    你可以做:

    [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 // ...
    

    【讨论】:

    • 谢谢!这正是我正在寻找的解决方案!我找到了另一个,但它不可靠,所以会试一试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多