Skip to content

Commit bfe971c

Browse files
committed
Rework .NET check to use the dotnet executable
Closes #102
1 parent 0c76554 commit bfe971c

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

CodeDependencies.iss

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,30 @@ begin
218218
Result := Dependency_String(' (x86)', ' (x64)');
219219
end;
220220
221-
function Dependency_IsNetCoreInstalled(const Version: String): Boolean;
221+
function Dependency_IsNetCoreInstalled(Runtime: String; Major, Minor, Revision: Word): Boolean;
222222
var
223223
ResultCode: Integer;
224+
Output: TExecOutput;
225+
LineIndex: Integer;
226+
LineParts: TArrayOfString;
227+
PackedVersion: Int64;
228+
LineMajor, LineMinor, LineRevision, LineBuild: Word;
224229
begin
225-
// source code: https://github.com/dotnet/deployment-tools/tree/main/src/clickonce/native/projects/NetCoreCheck
226-
if not FileExists(ExpandConstant('{tmp}{\}') + 'netcorecheck' + Dependency_ArchSuffix + '.exe') then begin
227-
ExtractTemporaryFile('netcorecheck' + Dependency_ArchSuffix + '.exe');
230+
Result := False;
231+
if ExecAndCaptureOutput(ExpandConstant('{cmd}'),'/C dotnet --list-runtimes', '', SW_HIDE, ewWaitUntilTerminated, ResultCode, Output) and (ResultCode = 0) then begin
232+
for LineIndex := 0 to Length(Output.StdOut) - 1 do begin
233+
LineParts := StringSplit(Trim(Output.StdOut[LineIndex]), [' '], stExcludeEmpty);
234+
235+
if (Length(LineParts) > 1) and (Lowercase(LineParts[0]) = Lowercase(Runtime)) and StrToVersion(LineParts[1], PackedVersion) then begin
236+
UnpackVersionComponents(PackedVersion, LineMajor, LineMinor, LineRevision, LineBuild);
237+
238+
if (LineMajor = Major) and (LineMinor = Minor) and (LineRevision >= Revision) then begin
239+
Result := True;
240+
break;
241+
end;
242+
end;
243+
end;
228244
end;
229-
Result := ShellExec('', ExpandConstant('{tmp}{\}') + 'netcorecheck' + Dependency_ArchSuffix + '.exe', Version, '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and (ResultCode = 0);
230245
end;
231246
232247
procedure Dependency_AddDotNet35;
@@ -318,7 +333,7 @@ end;
318333
procedure Dependency_AddNetCore31;
319334
begin
320335
// https://dotnet.microsoft.com/download/dotnet-core/3.1
321-
if not Dependency_IsNetCoreInstalled('-n Microsoft.NETCore.App -v 3.1.32') then begin
336+
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App', 3, 1, 32) then begin
322337
Dependency_Add('netcore31' + Dependency_ArchSuffix + '.exe',
323338
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
324339
'.NET Core Runtime 3.1.32' + Dependency_ArchTitle,
@@ -330,7 +345,7 @@ end;
330345
procedure Dependency_AddNetCore31Asp;
331346
begin
332347
// https://dotnet.microsoft.com/download/dotnet-core/3.1
333-
if not Dependency_IsNetCoreInstalled('-n Microsoft.AspNetCore.App -v 3.1.32') then begin
348+
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App', 3, 1, 32) then begin
334349
Dependency_Add('netcore31asp' + Dependency_ArchSuffix + '.exe',
335350
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
336351
'ASP.NET Core Runtime 3.1.32' + Dependency_ArchTitle,
@@ -342,7 +357,7 @@ end;
342357
procedure Dependency_AddNetCore31Desktop;
343358
begin
344359
// https://dotnet.microsoft.com/download/dotnet-core/3.1
345-
if not Dependency_IsNetCoreInstalled('-n Microsoft.WindowsDesktop.App -v 3.1.32') then begin
360+
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App', 3, 1, 32) then begin
346361
Dependency_Add('netcore31desktop' + Dependency_ArchSuffix + '.exe',
347362
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
348363
'.NET Desktop Runtime 3.1.32' + Dependency_ArchTitle,
@@ -354,7 +369,7 @@ end;
354369
procedure Dependency_AddDotNet50;
355370
begin
356371
// https://dotnet.microsoft.com/download/dotnet/5.0
357-
if not Dependency_IsNetCoreInstalled('-n Microsoft.NETCore.App -v 5.0.17') then begin
372+
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App', 5, 0, 17) then begin
358373
Dependency_Add('dotnet50' + Dependency_ArchSuffix + '.exe',
359374
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
360375
'.NET Runtime 5.0.17' + Dependency_ArchTitle,
@@ -366,7 +381,7 @@ end;
366381
procedure Dependency_AddDotNet50Asp;
367382
begin
368383
// https://dotnet.microsoft.com/download/dotnet/5.0
369-
if not Dependency_IsNetCoreInstalled('-n Microsoft.AspNetCore.App -v 5.0.17') then begin
384+
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App', 5, 0, 17) then begin
370385
Dependency_Add('dotnet50asp' + Dependency_ArchSuffix + '.exe',
371386
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
372387
'ASP.NET Core Runtime 5.0.17' + Dependency_ArchTitle,
@@ -378,7 +393,7 @@ end;
378393
procedure Dependency_AddDotNet50Desktop;
379394
begin
380395
// https://dotnet.microsoft.com/download/dotnet/5.0
381-
if not Dependency_IsNetCoreInstalled('-n Microsoft.WindowsDesktop.App -v 5.0.17') then begin
396+
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App', 5, 0, 17) then begin
382397
Dependency_Add('dotnet50desktop' + Dependency_ArchSuffix + '.exe',
383398
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
384399
'.NET Desktop Runtime 5.0.17' + Dependency_ArchTitle,
@@ -390,7 +405,7 @@ end;
390405
procedure Dependency_AddDotNet60;
391406
begin
392407
// https://dotnet.microsoft.com/download/dotnet/6.0
393-
if not Dependency_IsNetCoreInstalled('-n Microsoft.NETCore.App -v 6.0.20') then begin
408+
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App', 6, 0, 20) then begin
394409
Dependency_Add('dotnet60' + Dependency_ArchSuffix + '.exe',
395410
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
396411
'.NET Runtime 6.0.20' + Dependency_ArchTitle,
@@ -402,7 +417,7 @@ end;
402417
procedure Dependency_AddDotNet60Asp;
403418
begin
404419
// https://dotnet.microsoft.com/download/dotnet/6.0
405-
if not Dependency_IsNetCoreInstalled('-n Microsoft.AspNetCore.App -v 6.0.20') then begin
420+
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App', 6, 0, 20) then begin
406421
Dependency_Add('dotnet60asp' + Dependency_ArchSuffix + '.exe',
407422
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
408423
'ASP.NET Core Runtime 6.0.20' + Dependency_ArchTitle,
@@ -414,7 +429,7 @@ end;
414429
procedure Dependency_AddDotNet60Desktop;
415430
begin
416431
// https://dotnet.microsoft.com/download/dotnet/6.0
417-
if not Dependency_IsNetCoreInstalled('-n Microsoft.WindowsDesktop.App -v 6.0.20') then begin
432+
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App', 6, 0, 20) then begin
418433
Dependency_Add('dotnet60desktop' + Dependency_ArchSuffix + '.exe',
419434
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
420435
'.NET Desktop Runtime 6.0.20' + Dependency_ArchTitle,
@@ -426,7 +441,7 @@ end;
426441
procedure Dependency_AddDotNet70;
427442
begin
428443
// https://dotnet.microsoft.com/download/dotnet/7.0
429-
if not Dependency_IsNetCoreInstalled('-n Microsoft.NETCore.App -v 7.0.9') then begin
444+
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App', 7, 0, 9) then begin
430445
Dependency_Add('dotnet70' + Dependency_ArchSuffix + '.exe',
431446
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
432447
'.NET Runtime 7.0.9' + Dependency_ArchTitle,
@@ -438,7 +453,7 @@ end;
438453
procedure Dependency_AddDotNet70Asp;
439454
begin
440455
// https://dotnet.microsoft.com/download/dotnet/7.0
441-
if not Dependency_IsNetCoreInstalled('-n Microsoft.AspNetCore.App -v 7.0.9') then begin
456+
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App', 7, 0, 9) then begin
442457
Dependency_Add('dotnet70asp' + Dependency_ArchSuffix + '.exe',
443458
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
444459
'ASP.NET Core Runtime 7.0.9' + Dependency_ArchTitle,
@@ -450,7 +465,7 @@ end;
450465
procedure Dependency_AddDotNet70Desktop;
451466
begin
452467
// https://dotnet.microsoft.com/download/dotnet/7.0
453-
if not Dependency_IsNetCoreInstalled('-n Microsoft.WindowsDesktop.App -v 7.0.9') then begin
468+
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App', 7, 0, 9) then begin
454469
Dependency_Add('dotnet70desktop' + Dependency_ArchSuffix + '.exe',
455470
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
456471
'.NET Desktop Runtime 7.0.9' + Dependency_ArchTitle,
@@ -463,7 +478,7 @@ end;
463478
procedure Dependency_AddDotNet80;
464479
begin
465480
// https://dotnet.microsoft.com/download/dotnet/8.0
466-
if not Dependency_IsNetCoreInstalled('-n Microsoft.NETCore.App -v 8.0.10') then begin
481+
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App', 8, 0, 10) then begin
467482
Dependency_Add('dotnet80' + Dependency_ArchSuffix + '.exe',
468483
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
469484
'.NET Runtime 8.0.10' + Dependency_ArchTitle,
@@ -475,7 +490,7 @@ end;
475490
procedure Dependency_AddDotNet80Asp;
476491
begin
477492
// https://dotnet.microsoft.com/download/dotnet/8.0
478-
if not Dependency_IsNetCoreInstalled('-n Microsoft.AspNetCore.App -v 8.0.10') then begin
493+
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App', 8, 0, 10) then begin
479494
Dependency_Add('dotnet80asp' + Dependency_ArchSuffix + '.exe',
480495
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
481496
'ASP.NET Core Runtime 8.0.10' + Dependency_ArchTitle,
@@ -487,7 +502,7 @@ end;
487502
procedure Dependency_AddDotNet80Desktop;
488503
begin
489504
// https://dotnet.microsoft.com/download/dotnet/8.0
490-
if not Dependency_IsNetCoreInstalled('-n Microsoft.WindowsDesktop.App -v 8.0.10') then begin
505+
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App', 8, 0, 10) then begin
491506
Dependency_Add('dotnet80desktop' + Dependency_ArchSuffix + '.exe',
492507
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
493508
'.NET Desktop Runtime 8.0.10' + Dependency_ArchTitle,
@@ -499,7 +514,7 @@ end;
499514
procedure Dependency_AddDotNet90;
500515
begin
501516
// https://dotnet.microsoft.com/download/dotnet/9.0
502-
if not Dependency_IsNetCoreInstalled('-n Microsoft.NETCore.App -v 9.0.0') then begin
517+
if not Dependency_IsNetCoreInstalled('Microsoft.NETCore.App', 9, 0, 0) then begin
503518
Dependency_Add('dotnet90' + Dependency_ArchSuffix + '.exe',
504519
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
505520
'.NET Runtime 9.0.0' + Dependency_ArchTitle,
@@ -511,7 +526,7 @@ end;
511526
procedure Dependency_AddDotNet90Asp;
512527
begin
513528
// https://dotnet.microsoft.com/download/dotnet/9.0
514-
if not Dependency_IsNetCoreInstalled('-n Microsoft.AspNetCore.App -v 9.0.0') then begin
529+
if not Dependency_IsNetCoreInstalled('Microsoft.AspNetCore.App', 9, 0, 0) then begin
515530
Dependency_Add('dotnet90asp' + Dependency_ArchSuffix + '.exe',
516531
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
517532
'ASP.NET Core Runtime 9.0.0' + Dependency_ArchTitle,
@@ -523,7 +538,7 @@ end;
523538
procedure Dependency_AddDotNet90Desktop;
524539
begin
525540
// https://dotnet.microsoft.com/download/dotnet/9.0
526-
if not Dependency_IsNetCoreInstalled('-n Microsoft.WindowsDesktop.App -v 9.0.0') then begin
541+
if not Dependency_IsNetCoreInstalled('Microsoft.WindowsDesktop.App', 9, 0, 0) then begin
527542
Dependency_Add('dotnet90desktop' + Dependency_ArchSuffix + '.exe',
528543
'/lcid ' + IntToStr(GetUILanguage) + ' /passive /norestart',
529544
'.NET Desktop Runtime 9.0.0' + Dependency_ArchTitle,
@@ -759,13 +774,6 @@ begin
759774
end;
760775
761776
[Files]
762-
#ifdef Dependency_Path_NetCoreCheck
763-
; download netcorecheck.exe: https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x86
764-
; download netcorecheck_x64.exe: https://www.nuget.org/packages/Microsoft.NET.Tools.NETCoreCheck.x64
765-
Source: "{#Dependency_Path_NetCoreCheck}netcorecheck.exe"; Flags: dontcopy noencryption
766-
Source: "{#Dependency_Path_NetCoreCheck}netcorecheck_x64.exe"; Flags: dontcopy noencryption
767-
#endif
768-
769777
#ifdef Dependency_Path_DirectX
770778
Source: "{#Dependency_Path_DirectX}dxwebsetup.exe"; Flags: dontcopy noencryption
771779
#endif

ExampleSetup.iss

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
; https://github.com/DomGries/InnoDependencyInstaller
22

33

4-
; requires netcorecheck.exe and netcorecheck_x64.exe (see CodeDependencies.iss)
5-
#define public Dependency_Path_NetCoreCheck "dependencies\"
6-
74
; requires dxwebsetup.exe (see CodeDependencies.iss)
85
;#define public Dependency_Path_DirectX "dependencies\"
96

@@ -70,7 +67,6 @@ begin
7067
Dependency_AddDotNet47;
7168
Dependency_AddDotNet48;
7269
73-
#ifdef Dependency_Path_NetCoreCheck
7470
Dependency_AddNetCore31;
7571
Dependency_AddNetCore31Asp;
7672
Dependency_AddNetCore31Desktop;
@@ -89,7 +85,6 @@ begin
8985
Dependency_AddDotNet90;
9086
Dependency_AddDotNet90Asp;
9187
Dependency_AddDotNet90Desktop;
92-
#endif
9388
9489
Dependency_AddVC2005;
9590
Dependency_AddVC2008;

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Installation and Usage
88

9-
1. Download and install [Inno Setup 6.2+](https://www.jrsoftware.org/isinfo.php).
9+
1. Download and install [Inno Setup 6.4+](https://www.jrsoftware.org/isinfo.php).
1010
2. Download [this repository](https://github.com/DomGries/InnoDependencyInstaller/archive/master.zip) or clone it.
1111
3. Open the extracted _ExampleSetup.iss_ file.
1212
4. Comment out dependency function calls inside _InitializeSetup_ function to disable installing them:

0 commit comments

Comments
 (0)