Home > Net >  Is there a way to determine via registry .NET Core version with NSIS?
Is there a way to determine via registry .NET Core version with NSIS?

Time:08-13

I need to create a setup file using NSIS. Part of the process is to check the Net Core version. Basing this on the registry entry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET Core\Shared Framework I have the following

  ReadRegStr $0 HKLM "SOFTWARE\Microsoft\ASP.NET Core\Shared Framework" "v6.0" 
  StrCmp $0 0 Net6 NoNet6
NoNet6:
  MessageBox MB_OK ".NET 6.0 or later version was not found! [$0]"
  Abort
Net6:
    MessageBox MB_OK ".NET 6.0 or later version was found! [$0]"

This does not work. What I would like to do is check to see if the subfolder "v6.0" exists, this way I would know that core version 6 exists. If it doesn't then I can pop a message and abort the setup.

Is there a way to compare the name of the subfolder to "v6.0"?

Any help would be appreciated.

CodePudding user response:

You can see all runtimes/sdk installed here. Though you should probably use something like dotnet --version, or dotnet --info

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost

it will show you this:

enter image description here

Here is some C# to read the value.

var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost\");
           
var version = key.GetValue("Version").Dump();

NSIS - ReadRegStr $3 HKLM "HKEY_LOCAL_MACHINE\SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost\" "Version"

CodePudding user response:

Part of the problem besides my registry entry was how NSIS gets information. I had to set the registry view to 64bit.

  ; check for .NET 6 properly installed
  SetRegView 64
  ReadRegStr $0 HKLM SOFTWARE\dotnet\Setup\InstalledVersions\x64\sharedhost Version
  IntCmp $0 6 Net6 NoNet6 Net6
NoNet6:
  MessageBox MB_OK ".NET 6.0 or later version was NOT found! [$0]"
  Abort
Net6:
  MessageBox MB_OK ".NET 6.0 or later version was found! [$0]"

Thats to Mathis1337 for the registry entry suggestion. Adding the "SetRegView 64" got it working.

  • Related