All, I am aware of the following methods to check the framework version in NSIS. For .NET4.0+ I currently use
Function IsDotNetInstalled
StrCpy $0 "0"
StrCpy $1 "SOFTWARE\Microsoft\.NETFramework" ; Registry entry to look in.
StrCpy $2 0
StartEnum:
; Enumerate the versions installed.
EnumRegKey $3 HKLM "$1\policy" $2
; If we don't find any versions installed, it's not here.
StrCmp $3 "" noDotNet notEmpty
; We found something.
notEmpty:
; Find out if the RegKey starts with 'v'.
; If it doesn't, goto the next key.
StrCpy $4 $3 1 0
StrCmp $4 "v" +1 goNext
StrCpy $4 $3 1 1
; It starts with 'v'. Now check to see how the installed major version
; relates to our required major version.
; If it's equal check the minor version, if it's greater,
; we found a good RegKey.
IntCmp $4 ${DOT_MAJOR} +1 goNext yesDotNetReg
; Check the minor version. If it's equal or greater to our requested
; version then we're good.
StrCpy $4 $3 1 3
IntCmp $4 ${DOT_MINOR} yesDotNetReg goNext yesDotNetReg
goNext:
; Go to the next RegKey.
IntOp $2 $2 + 1
goto StartEnum
yesDotNetReg:
; Now that we've found a good RegKey, let's make sure it's actually
; installed by getting the install path and checking to see if the
; mscorlib.dll exists.
EnumRegValue $2 HKLM "$1\policy\$3" 0
; $2 should equal whatever comes after the major and minor versions
; (ie, v1.1.4322)
StrCmp $2 "" noDotNet
ReadRegStr $4 HKLM $1 "InstallRoot"
; Hopefully the install root isn't empty.
StrCmp $4 "" noDotNet
; Build the actuall directory path to mscorlib.dll.
StrCpy $4 "$4$3.$2\mscorlib.dll"
IfFileExists $4 yesDotNet noDotNet
noDotNet:
; No, something went wrong along the way. Looks like the
; proper .NET Framework isn't installed.
MessageBox MB_ICONEXCLAMATION "To install UserCost, Microsoft's .NET Framework v${DOT_MAJOR}.${DOT_MINOR} \
(or higher) must be installed. Cannot proceed with the installation!"
${OpenURL} "${WWW_MS_DOTNET4}"
Abort
yesDotNet:
; Everything checks out. Proceed with the rest of the installation.
FunctionEnd
This works very well for .NET4.0, but I have now extended my application to utilise the async
/await
features and subsequently need users to install .NET4.5+. The above method is not suitable as the installation for .NET4.5 now does not use the regestry path 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\Policy" to store any new information, that is that path does not seem to hold a value that changes between .NET4.0 and 4.5. Now I have seen the following posts:
which uses the registry path/entry 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP' to do the checks. Now this also does bot work as the entry does not change from .NET4.0 to 4.5. I notice that there is and entry called 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft.NETFramework\v4.0.30319\SKUs.NETFramework,Version=v4.5' can I use this to check the Framework version invariably?
Is there an offical line of the way to check for .NET4.5 using NSIS?
Thanks for your time.
Note: subsequently some installation of .NET4.5 my users have performed have had registry values for
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
a DWORD value named Release
was not 378389
but 378181
. Making this change seemed to resolve the problem as the entry for the Release
is not in the registry for .NET4.5 and below.
Now that .NET Framework 4.5.1 is available the actual value of DWORD named Release in the registry needs to be checked, not just its existence.
A value of 378758 means that .NET Framework 4.5.1 is installed, however, as described here this value is 378675 on Windows 8.1.
If you're looking for options with .net framework 4.0+ (and above) including
you can also check this plug-in for NSIS: DotNetChecker
Here is a function that I wrote that checks for, and downloads if needed, .NET 4.5. In addition, the code also looks for a local copy of the .NET installer - in case you were to put your installer onto a CD or USB drive or something. Supports Silent and Non-Silent installs, as well as setting the Reboot flag. The function is self-contained, but expects you to include LogicLib (which is included with the basic NSIS install).
This is the code that I wrote for what will be the installer for my Rachel's Story books.
Yes there is an official way to check if .NET Framework 4.5 is installed, even if it's not really friendly. From MSDN:
It means you first have to check if 4.0 is installed and then to check if there is a value named
Release
inHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
, if so then 4.5 is already installed (I think you can skip the check for a pre-release version).EDIT: check this post here on SO for details about detecting older installed .NET versions and this MSDN article to distinguish between for 4.5.x versions.
In the end I went with the following function which utilises the answer above. This method first creates a directory
"$INSTDIR\dotNETFramework"
which contains the .NET web installer:This method seemlessley launches the .NET4.5 installer if there is an internet connection and returns after the installation is complete.
I hope this helps someone else.
Here's a simple NSIS Function that checks for .NET versions (works for 4.5, 4.5.1, 4.5.2 and 4.6). The numeric comparisons are based on MSDN.
Place the function in your NSIS file and invoke it like so
Here is the function.