gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 03:23:37 24 4
gpt4 key购买 nike

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

最佳答案

基于:

你可以这样做:

[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-core - 检查 Inno Setup 中是否安装了 .NET 5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72479992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com