13

すべて、NSISでフレームワークのバージョンを確認するための次の方法を知っています。.NET4.0 +の場合、現在使用しています

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のインストールでは、新しい情報を格納するために再取得パス'HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft.NETFramework \ Policy "を使用しないため、適切ではありません。つまり、パスは次の値を保持していないようです。 .NET4.0と4.5の間の変更。これで、次の投稿が表示されました。

.NET4.5を使用したNSISインストーラー

これは、レジストリパス/エントリ'HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ NET Framework Setup\NDP'を使用してチェックを実行します。エントリが.NET4.0から4.5に変更されないため、これもボットの動作を実行します。'HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft.NETFramework \ v4.0.30319 \ SKUs.NETFramework、Version = v4.5'というエントリがあることに気付きました。これを使用して、Frameworkのバージョンを常に確認できますか?

NSISを使用して.NET4.5をチェックする方法の公式ラインはありますか?

御時間ありがとうございます。


注:その後、ユーザーが実行した.NET4.5の一部のインストールには、次のレジストリ値があります。

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full 

名前の付いたDWORD値はReleaseではありませんでし378389378181Releaseのエントリが.NET4.5以下のレジストリにないため、この変更を行うと問題が解決したようです。

4

6 に答える 6

25

はい、.NET Framework 4.5 がインストールされているかどうかを確認する公式の方法があります。MSDNから:

.NET Framework 4.5 または .NET Framework 4 がインストールされているかどうかはHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full、レジストリのサブキーでDWORDという名前の値を確認することでテストできますRelease。これが存在するDWORDということは、.NET Framework 4.5 がそのコンピューターにインストールされていることを示しています。Release の値はバージョン番号です。.NET Framework 4.5 の最終リリース バージョンがインストールされているかどうかを確認するには、378389 以上の値を確認します。

http://msdn.microsoft.com/en-us/library/hh925568.aspx

つまり、最初に 4.0 がインストールされているかどうかを確認してから、Releaseinという名前の値があるかどうかを確認する必要がありますHKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full。その場合は、4.5 が既にインストールされています (プレリリース バージョンのチェックをスキップできると思います)。

編集:インストールされている古い .NET バージョンの検出の詳細については、SO のこの投稿を確認し、4.5.x バージョンを区別するには、このMSDN の記事を確認してください。

于 2013-03-05T15:35:09.017 に答える
5

最後に、上記の答えを利用した次の関数を使用しました。このメソッドは、最初"$INSTDIR\dotNETFramework"に.NETWebインストーラーを含むディレクトリを作成します。

Function CheckAndInstallDotNet
    ; Installer dotNetFx45_Full_setup.exe avalible from http://msdn.microsoft.com/en-us/library/5a4x27ek.aspx
    ; 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:
        MessageBox MB_YESNO|MB_ICONQUESTION ".NET Framework 4.5+ is required for ProgramX2013, \
            do you want to launch the web installer? This requires a valid internet connection." IDYES InstallDotNet IDNO Cancel 
        Cancel:
            MessageBox MB_ICONEXCLAMATION "To install ProgramX, Microsoft's .NET Framework v${DOT_MAJOR}.${DOT_MINOR} \
                (or higher) must be installed. Cannot proceed with the installation!"
            ${OpenURL} "${WWW_MS_DOTNET4_5}"
            RMDir /r "$INSTDIR" 
            SetOutPath "$PROGRAMFILES"
            RMDir "$INSTDIR" 
            Abort

        ; Install .NET4.5.
        InstallDotNet:
            DetailPrint "Installing Microsoft .NET Framework 4.5"
            SetDetailsPrint listonly
            ExecWait '"$INSTDIR\dotNETFramework\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}

    ; Now remove the dotNETFramework directory and contents.
    RMDir /r "$INSTDIR\dotNETFramework" 
FunctionEnd

このメソッドは、インターネット接続がある場合に.NET4.5インストーラーを起動し、インストールの完了後に戻ります。

これが他の誰かに役立つことを願っています。

于 2013-03-07T09:07:26.707 に答える
5

これは、.NET 4.5 をチェックし、必要に応じてダウンロードする、私が作成した関数です。さらに、コードは .NET インストーラーのローカル コピーも探します (インストーラーを CD や USB ドライブなどに置く場合)。サイレント インストールと非サイレント インストールをサポートし、再起動フラグを設定します。この関数は自己完結型ですが、LogicLib (基本的な NSIS インストールに含まれています) を含める必要があります。

これは、Rachel's Story ブックのインストーラー用に私が書いたコードです。

Function CheckAndDownloadDotNet45
# Let's see if the user has the .NET Framework 4.5 installed on their system or not
# Remember: you need Vista SP2 or 7 SP1.  It is built in to Windows 8, and not needed
# In case you're wondering, running this code on Windows 8 will correctly return is_equal
# or is_greater (maybe Microsoft releases .NET 4.5 SP1 for example)

# Set up our Variables
Var /GLOBAL dotNET45IsThere
Var /GLOBAL dotNET_CMD_LINE
Var /GLOBAL EXIT_CODE

ReadRegDWORD $dotNET45IsThere HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Release"
IntCmp $dotNET45IsThere 378389 is_equal is_less is_greater

is_equal:
    Goto done_compare_not_needed
is_greater:
    # Useful if, for example, Microsoft releases .NET 4.5 SP1
    # We want to be able to simply skip install since it's not
    # needed on this system
    Goto done_compare_not_needed
is_less:
    Goto done_compare_needed

done_compare_needed:
    #.NET Framework 4.5 install is *NEEDED*

    # Microsoft Download Center EXE:
    # Web Bootstrapper: http://go.microsoft.com/fwlink/?LinkId=225704
    # Full Download: http://go.microsoft.com/fwlink/?LinkId=225702

    # Setup looks for components\dotNET45Full.exe relative to the install EXE location
    # This allows the installer to be placed on a USB stick (for computers without internet connections)
    # If the .NET Framework 4.5 installer is *NOT* found, Setup will connect to Microsoft's website
    # and download it for you

    # Reboot Required with these Exit Codes:
    # 1641 or 3010

    # Command Line Switches:
    # /showrmui /passive /norestart

    # Silent Command Line Switches:
    # /q /norestart


    # Let's see if the user is doing a Silent install or not
    IfSilent is_quiet is_not_quiet

    is_quiet:
        StrCpy $dotNET_CMD_LINE "/q /norestart"
        Goto LookForLocalFile
    is_not_quiet:
        StrCpy $dotNET_CMD_LINE "/showrmui /passive /norestart"
        Goto LookForLocalFile

    LookForLocalFile:
        # Let's see if the user stored the Full Installer
        IfFileExists "$EXEPATH\components\dotNET45Full.exe" do_local_install do_network_install

        do_local_install:
            # .NET Framework found on the local disk.  Use this copy

            ExecWait '"$EXEPATH\components\dotNET45Full.exe" $dotNET_CMD_LINE' $EXIT_CODE
            Goto is_reboot_requested

        # Now, let's Download the .NET
        do_network_install:

            Var /GLOBAL dotNetDidDownload
            NSISdl::download "http://go.microsoft.com/fwlink/?LinkId=225704" "$TEMP\dotNET45Web.exe" $dotNetDidDownload

            StrCmp $dotNetDidDownload success fail
            success:
                ExecWait '"$TEMP\dotNET45Web.exe" $dotNET_CMD_LINE' $EXIT_CODE
                Goto is_reboot_requested

            fail:
                MessageBox MB_OK|MB_ICONEXCLAMATION "Unable to download .NET Framework.  ${PRODUCT_NAME} will be installed, but will not function without the Framework!"
                Goto done_dotNET_function

            # $EXIT_CODE contains the return codes.  1641 and 3010 means a Reboot has been requested
            is_reboot_requested:
                ${If} $EXIT_CODE = 1641
                ${OrIf} $EXIT_CODE = 3010
                    SetRebootFlag true
                ${EndIf}

done_compare_not_needed:
    # Done dotNET Install
    Goto done_dotNET_function

#exit the function
done_dotNET_function:

FunctionEnd
于 2013-03-07T02:15:59.170 に答える
1

.net フレームワーク 4.0+ (およびそれ以降) を含むオプションを探している場合

  • .net 4.5
  • .net 4.5.1

NSIS のこのプラグインを確認することもできます: DotNetChecker

于 2014-10-07T01:49:39.953 に答える