I'm using inno setup for the first time, and I've been tormented with this problem for a day, and desperately need help. I use VS to compile a WPF program, which depends on the .net6 runtime. I want to detect whether the user has the .net6 runtime during installation. If not, install the corresponding .net6 runtime. I want to know how to achieve it through inno setup I have downloaded the x86 and x64 versions of the .net6 runtime
Asked
Active
Viewed 159 times
1 Answers
0
This script uses the downloader and should do the job:
[Setup]
AppName=SO Demo Code
AppVersion=<Your Verision>
DefaultDirName={pf}\SO Demo Code
[Files]
Source: "<Your Path>\dotnet-runtime-downloader.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
[Code]
function IsDotNet6Installed: Boolean;
var
regVersion: Cardinal;
begin
Result := RegQueryDWordValue(HKLM, 'SOFTWARE\Microsoft\NET Framework Setup\NDP\v6.0', 'Version', regVersion);
end;
function InitializeSetup: Boolean;
var
dotNet6Installed: Boolean;
dotNetDownloaderPath: string;
dotNetDownloaderArgs: string;
downloadResultCode: Integer;
begin
Result := True;
dotNet6Installed := IsDotNet6Installed;
if not dotNet6Installed then
begin
MsgBox('The .NET 6 runtime is required. Downloading and installing it now.', mbInformation, MB_OK);
dotNetDownloaderPath := ExpandConstant('{tmp}\dotnet-runtime-downloader.exe');
dotNetDownloaderArgs := 'https://path/to/dotnet-runtime-x86-6.0.0-win.exe,https://path/to/dotnet-runtime-x64-6.0.0-win.exe';
ExtractTemporaryFile('dotnet-runtime-downloader.exe');
// Run the downloader to fetch the .NET 6 runtime installers
Exec(dotNetDownloaderPath, dotNetDownloaderArgs, '', SW_HIDE, ewWaitUntilTerminated, downloadResultCode);
dotNet6Installed := IsDotNet6Installed;
if not dotNet6Installed then
begin
MsgBox('Failed to download and install the .NET 6 runtime. Setup will now exit.', mbError, MB_OK);
Result := False;
end;
end;
end;

marsh-wiggle
- 2,508
- 3
- 35
- 52