NSIS Installer with .NET 4.5
Asked Answered
H

1

7

I'm after some code snippets for NSIS to detect and conditionally run the .NET 4.5 installer

This answer - NSIS Installer with .NET 4.0 - is too naive as checking only the presense of the registry key (not the value) will not discriminate between 4.0 and 4.5

Hendecahedron answered 11/10, 2012 at 22:11 Comment(0)
C
19

You shouldn't check for an exact version number. This will change in the future (as was the case for 4.0 > 4.5). Instead use the codes from the deployment guide.

In addition to that you should try to handle the reboot from .Net 4.5.

Function CheckAndInstallDotNet
    ; Magic numbers from http://msdn.microsoft.com/en-us/library/ee942965.aspx
    ClearErrors
    ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"

    IfErrors NotDetected

    ${If} $0 >= 378389

        DetailPrint "Microsoft .NET Framework 4.5 is installed ($0)"
    ${Else}
    NotDetected:
        DetailPrint "Installing Microsoft .NET Framework 4.5"
        SetDetailsPrint listonly
        ExecWait '"$INSTDIR\Tools\dotNetFx45_Full_setup.exe" /passive /norestart' $0
        ${If} $0 == 3010 
        ${OrIf} $0 == 1641
            DetailPrint "Microsoft .NET Framework 4.5 installer requested reboot"
            SetRebootFlag true
        ${EndIf}
        SetDetailsPrint lastused
        DetailPrint "Microsoft .NET Framework 4.5 installer returned $0"
    ${EndIf}

FunctionEnd
Coles answered 16/10, 2012 at 0:9 Comment(7)
great answer! I will delete my hack answer in shame! Also edited in the 1641 code check for reboot (your original version compiled without error)Hendecahedron
Thanks this is exactly what I needed. Saved me a bunch of time!Devland
I've been trying different snippets for this but yours is by far the most elegant and readable solution I've seen. +1Nannette
what if they just have .net5 or another future major version of .net installed? will this method still work? presumably the next major versions will be backwards compatible so the user wouldn't need to install 4.5 if 5,6 or whatever is installed?Pearman
Consider this registry key public surface area. .Net guarantees that it will be present for all future versions that will run .Net 4.x apps.Coles
Can anyone show me an example of how to call this function? I call this function as first step in the install section. The installer of .NET framework starts verifying files and then it is blocked saying that it waits for another installer to finish. That other installer is my installer that started the .NET framework. And my installer waits for the .NET framework installer to finish. So I created a deadlock...Allin
@Pearman .Net Framework 4.8 - the latest version! .Net framework they won't be any newer. Meet the new .Net Core 3.0, 3.1, 5.0 ...Honorable

© 2022 - 2024 — McMap. All rights reserved.