Search code examples
.net.net-corensis

How to detect net core 3.1 windows desktop app runtime is installed through NSIS script


I have a .net windows application installation setup created using NSIS (Nullsoft Scriptable Install System). All the relevant .net framework and other dependencies are checked and installed through the NSIS script. This setup was initially built for .net framework 4.8 application. But now I want to upgrade it to install a .net core 3.1 application. Can someone please help me on how we can detect the target machine has .net core 3.1 windows desktop runtime is installed through the NSIS script?


Solution

  • Detecting .NET is always a joy. Detecting it in NSIS should be fairly simple once you know the general method but even finding that information is hard.

    I don't have .NET Core installed so I cannot verify any of this but from what I gather you should look for the global install location in the registry:

    !include LogicLib.nsh
    SetRegView 32 ; Always use the 32-bit view
    ReadRegStr $1 HKLM "SOFTWARE\dotnet\Setup\InstalledVersions\x86" "InstallLocation" ; x86, x64, arm or arm64 and only for Core v3 and later
    SetRegView lastused
    ${If} $1 == ""
        StrCpy $1 "$ProgramFiles32\dotnet" ; might want to change this if not x86?
    ${EndIf}
    

    Once you know the location (or hope the default location exists) you are supposed to execute dotnet.exe with a command line switch. Depending on who you ask, this might be --info, --version or --list-runtimes.

    nsExec::ExecToStack '"$1\dotnet.exe" --info'
    Pop $0 ; Return
    Pop $2 ; Output
    ${If} $0 != "error"
        MessageBox mb_ok "TODO: Parse $2"
    ${EndIf}