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



我有以下。iss脚本来编译我正在使用。net 5.0的游戏启动器。目前,它每次都尝试从安装程序中安装。net 5.0,而不是先检查是否需要。我已经找到了大量的资源来告诉你如何在。net框架中做到这一点,但对于。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: "..binReleasenet5.0-windows*"; DestDir: "{app}"; 
Flags: ignoreversion recursesubdirs;
Source: "Resourceswindowsdesktop-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...

基于:

  • 如何在Inno Setup中获得execec 'ed程序的输出?
  • 如何检查。net是否已经安装

你可以这样做:

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