所有的,我知道以下方法檢查NSIS中的框架版本。對於.NET4.0 +我目前使用使用NSIS檢查.NET4.5 +
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
這都非常好,.NET4.0,但現在我已經延長我的應用程序利用async
/await
功能,隨後需要用戶安裝.NET4.5 +。上述方法不適用,因爲.NET4.5的安裝現在不使用regestry路徑「HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft.NETFramework \ Policy」來存儲任何新信息,即該路徑似乎不具有值.NET4.0和4.5之間的變化現在我已經看到了以下職位:
它使用的註冊表路徑/進入「HKEY_LOCAL_MACHINE \ SOFTWARE \微軟\ NET Framework安裝\ NDP」做檢查。現在,這也是機器人的工作,因爲入口不會從.NET4.0更改爲4.5。我注意到有和稱爲'HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft.NETFramework \ v4.0.30319 \ SKUs.NETFramework,版本= v4的條目。 5'我可以用它來檢查框架版本嗎?
是否有使用NSIS檢查.NET4.5的方法的一條主線?
謝謝你的時間。
注:隨後一些安裝.NET4.5我的用戶已經執行有註冊表值
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full
命名爲Release
一個DWORD值不378389
,但378181
。進行此更改似乎可以解決問題,因爲Release
的條目不在.NET4.5及更低版本的註冊表中。
這是一個高質量的答案。這些信息在哪裏由微軟提供 - 或者我們是否期望找到自己的信息?感謝您的時間... – MoonKnight 2013-03-05 15:42:03
我忘了引用[源代碼](http://msdn.microsoft.com/en-us/library/hh925568.aspx)。 – 2013-03-05 15:44:47
剛剛找到它。再次感謝... – MoonKnight 2013-03-05 15:49:20