DotNET: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(The default dotnet version was incorrect)
(I re-wrote DotNet.nsh to actually check version numbers. The install is also silent now, so no need for the dll)
Line 1: Line 1:
== Overview ==
== Overview ==
DotNET is a macro written to aid in the deployment of .NET Framework 2.0-based applications using NSIS.
DotNET is a macro written to aid in the deployment of .NET Framework 2.0-based applications using NSIS.
There is a [http://nsis.sourceforge.net/DotNet_plug-in plugin] that builds on top of the macro to make the installation step silent.


=== What it does ===
=== What it does ===
Line 11: Line 9:
=== Limitations ===
=== Limitations ===
* Only works for .NET Framework 2.0, not 1.0 or 1.1.
* Only works for .NET Framework 2.0, not 1.0 or 1.1.
* Does not process end-user's version to detect if it is newer than the required version.


== Usage ==
== Usage ==
Line 26: Line 23:
or
or
<highlight-nsis>!define DOTNET_VERSION "2.0.5"</highlight-nsis>
<highlight-nsis>!define DOTNET_VERSION "2.0.5"</highlight-nsis>
or
<highlight-nsis>!define DOTNET_VERSION "2"</highlight-nsis>


=== Using the Script ===
=== Using the Script ===
Line 43: Line 42:
<highlight-nsis>
<highlight-nsis>
# DotNET version checking macro.
# DotNET version checking macro.
# Written by AnarkiNet(AnarkiNet@gmail.com)
# Written by AnarkiNet(AnarkiNet@gmail.com) originally, modified by eyal0
# Downloads and runs the Microsoft .NET Framework version 2.0 Redistributable and runs it if the user does not have the correct version.
# Downloads and runs the Microsoft .NET Framework version 2.0 Redistributable and runs it if the user does not have the correct version.
;modifies the input to a version that can be compared like a string or num
!macro VerToNum VTN_output VTN_version
  ;MessageBox MB_OK "***VTN_version is ${VTN_version}"
  Push $0
  Push $1
  Push $2
  Push $3
  Push $4
 
  StrCpy $4 ${VTN_version}
  StrCpy $0 ""
  StrCpy $1 0
  ;MessageBox MB_OK "3**VTN_version is $4"
  ${DoUntil} $1 == 4
    ;MessageBox MB_OK "4**VTN_version is $4"
    ${StrTok} $2 $4 "." $1 "0"
    ;MessageBox MB_OK "***VTN_version is now $4"
    ;MessageBox MB_OK "***0 is $0"
    ;MessageBox MB_OK "***1 is $1"
    StrLen $3 $2
    ${DoUntil} $3 >= 6 ;until the current part is 6 digits long
      ;MessageBox MB_OK "2 is $2"
      StrCpy $2 "0$2"
      StrLen $3 $2
    ${Loop}
    StrCpy $0 $0$2
    IntOp $1 $1 + 1
  ${Loop}
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $0
  Pop ${VTN_output}
!macroend
!macro CheckDotNET
!macro CheckDotNET
!define DOTNET_URL "http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=0856eacb-4362-4b0d-8edd-aab15c5e04f5&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f6%2f7%2f567758a3-759e-473e-bf8f-52154438565a%2fdotnetfx.exe"
  !define DOTNET_URL "http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=0856eacb-4362-4b0d-8edd-aab15c5e04f5&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f6%2f7%2f567758a3-759e-473e-bf8f-52154438565a%2fdotnetfx.exe"
DetailPrint "Checking your .NET Framework version..."
  DetailPrint "Checking your .NET Framework version..."
Push $0
  Push $0
Push $1
  Push $1


System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i) i .r1"
  System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i) i .r1 ?u"
StrCmp $1 0 +2
  StrCmp $1 0 +2
StrCpy $0 "not found"
    StrCpy $0 "not found"


Pop $1
  Pop $1
Exch $0
  Exch $0
Pop $0
  Pop $0
${If} $0 == "not found"
  ${If} $0 == "not found"
DetailPrint ".NET Framework not found, download is required for program to run!"
  DetailPrint ".NET Framework not found, download is required for program to run!"
Goto InvalidDotNET
    Goto InvalidDotNET
${EndIf}
  ${EndIf}


StrLen $1 ${DOTNET_VERSION}
  ;at this point, $0 has maybe v2.345.678.
StrCpy $0 $0 $1 1
  Push $0
  Push $1
  StrCpy $0 $0 ${NSIS_MAX_STRLEN} 1 ;remove the starting "v", $0 has the installed version num
  StrCpy $1 ${DOTNET_VERSION}       ;$1 has the requested verison num
  !insertmacro VerToNum $0 $0 ;convert $0 to a 16 digit num
  !insertmacro VerToNum $1 $1 ;convert $1 to a 16 digit num


${If} $0 != ${DOTNET_VERSION}
  ${If} $0 S< $1
DetailPrint ".NET Framework Version found: $0, but does not match required version: ${DOTNET_VERSION}"
    Pop $1
Goto InvalidDotNET
    Pop $0
${EndIf}
    DetailPrint ".NET Framework Version found: $0, but does not match required version: ${DOTNET_VERSION}"
DetailPrint ".NET Framework Version found: $0, matches required version: ${DOTNET_VERSION}."
    Goto InvalidDotNET
Goto ValidDotNET
  ${EndIf}
  Pop $1
  Pop $0
  DetailPrint ".NET Framework Version found: $0, matches required version: ${DOTNET_VERSION}."
  Goto ValidDotNET


InvalidDotNET:
InvalidDotNET:
MessageBox MB_YESNO|MB_ICONEXCLAMATION \
  ${If} $0 == "not found"
"Your .NET Framework version: $0.$\nRequired Version: ${DOTNET_VERSION} or greater.$\nWould you like the installer to download the latest .NET Framework version from www.microsoft.com?$\nIf your version is newer, press No." \
    MessageBox MB_YESNO|MB_ICONEXCLAMATION \
IDYES Download IDNO ValidDotNET
    ".NET Framework not installed.$\nRequired Version: ${DOTNET_VERSION} or greater.$\nWould you like the installer to download the latest .NET Framework version from www.microsoft.com?" \
    IDYES Download IDNO ValidDotNET 
  ${Else}
    MessageBox MB_YESNO|MB_ICONEXCLAMATION \
    "Your .NET Framework version: $0.$\nRequired Version: ${DOTNET_VERSION} or greater.$\nWould you like the installer to download the latest .NET Framework version from www.microsoft.com?" \
    IDYES Download IDNO ValidDotNET
  ${EndIf}
Download:
  DetailPrint "Beginning download of latest .NET Framework version."
  NSISDL::download ${DOTNET_URL} "$TEMP\dotnetfx.exe"
  DetailPrint "Completed download."
  Pop $R0
  StrCmp $R0 "success" +2
    Abort "Download failed: $R0"
  DetailPrint "Pausing installation while downloaded .NET Framework installer runs."
  ExecWait 'dotnetfx.exe /q /c:"install /q"'
  DetailPrint "Completed .NET Framework install/update. Cleaning temporary files..."
  Delete "$TEMP\dotnetfx.exe"
  DetailPrint "Completed cleaning temporary files."


Download:
DetailPrint "Beginning download of latest .NET Framework version."
NSISDL::download ${DOTNET_URL} "$TEMP\dotnetfx.exe"
DetailPrint "Completed download."
Pop $R0
StrCmp $R0 "success" +3
MessageBox MB_OK "Download failed: $R0"
Quit
DetailPrint "Pausing installation while downloaded .NET Framework installer runs."
ExecWait '"$TEMP\dotnetfx.exe"'
DetailPrint "Completed .NET Framework install/update. Cleaning temporary files..."
Delete "$TEMP\dotnetfx.exe"
DetailPrint "Completed cleaning temporary files."
ValidDotNET:
ValidDotNET:
DetailPrint "Proceeding with remainder of installation..."
  DetailPrint "Proceeding with remainder of installation..."
!macroend
!macroend
</highlight-nsis></div>
</highlight-nsis></div>

Revision as of 17:03, 12 January 2007

Overview

DotNET is a macro written to aid in the deployment of .NET Framework 2.0-based applications using NSIS.

What it does

  1. Checks the version of the .NET framework on the end-user's computer.
  2. Prompts them with a yes/no dialog if their version is different than the defined DOTNET_VERSION in the installer's main script.
  3. If they press yes, the installer downloads the latest .NET Framework 2.0 installer and runs it.

Limitations

  • Only works for .NET Framework 2.0, not 1.0 or 1.1.

Usage

Including the Script

Save the Script contents as DotNET.nsh in the same folder as your main script, and put line in your main script like this:

!include "DotNET.nsh"

DotNet.nsh uses the ${if} function of LogicLib, so you also have to include it in your script:

!include LogicLib.nsh

Required Variables

Define the variable DOTNET_VERSION as the full or partial version of .NET Framework your app requires, like so:

!define DOTNET_VERSION "2.0.50727"

or

!define DOTNET_VERSION "2.0.5"

or

!define DOTNET_VERSION "2"

Using the Script

Insert the macro CheckDotNET into your script inside the first required section of the installer:

Section "Main Section (Required)"
	SectionIn RO
 
	!insertmacro CheckDotNET
 
	#Files here
SectionEnd

Script

# DotNET version checking macro.
# Written by AnarkiNet(AnarkiNet@gmail.com) originally, modified by eyal0
# Downloads and runs the Microsoft .NET Framework version 2.0 Redistributable and runs it if the user does not have the correct version.
;modifies the input to a version that can be compared like a string or num
!macro VerToNum VTN_output VTN_version
  ;MessageBox MB_OK "***VTN_version is ${VTN_version}"
  Push $0
  Push $1
  Push $2
  Push $3
  Push $4
 
  StrCpy $4 ${VTN_version}
  StrCpy $0 ""
  StrCpy $1 0
  ;MessageBox MB_OK "3**VTN_version is $4"
 
  ${DoUntil} $1 == 4
    ;MessageBox MB_OK "4**VTN_version is $4"
    ${StrTok} $2 $4 "." $1 "0"
    ;MessageBox MB_OK "***VTN_version is now $4"
    ;MessageBox MB_OK "***0 is $0"
    ;MessageBox MB_OK "***1 is $1"
    StrLen $3 $2
    ${DoUntil} $3 >= 6 ;until the current part is 6 digits long
      ;MessageBox MB_OK "2 is $2"
      StrCpy $2 "0$2"
      StrLen $3 $2
    ${Loop}
    StrCpy $0 $0$2
    IntOp $1 $1 + 1
  ${Loop}
 
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $0
  Pop ${VTN_output}
!macroend
 
!macro CheckDotNET
  !define DOTNET_URL "http://www.microsoft.com/downloads/info.aspx?na=90&p=&SrcDisplayLang=en&SrcCategoryId=&SrcFamilyId=0856eacb-4362-4b0d-8edd-aab15c5e04f5&u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f5%2f6%2f7%2f567758a3-759e-473e-bf8f-52154438565a%2fdotnetfx.exe"
  DetailPrint "Checking your .NET Framework version..."
  Push $0
  Push $1
 
  System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i) i .r1 ?u"
  StrCmp $1 0 +2
    StrCpy $0 "not found"
 
  Pop $1
  Exch $0
  Pop $0
  ${If} $0 == "not found"
  	DetailPrint ".NET Framework not found, download is required for program to run!"
    Goto InvalidDotNET
  ${EndIf}
 
  ;at this point, $0 has maybe v2.345.678.
  Push $0
  Push $1
  StrCpy $0 $0 ${NSIS_MAX_STRLEN} 1 ;remove the starting "v", $0 has the installed version num
  StrCpy $1 ${DOTNET_VERSION}       ;$1 has the requested verison num
  !insertmacro VerToNum $0 $0 ;convert $0 to a 16 digit num
  !insertmacro VerToNum $1 $1 ;convert $1 to a 16 digit num
 
  ${If} $0 S< $1
    Pop $1
    Pop $0
    DetailPrint ".NET Framework Version found: $0, but does not match required version: ${DOTNET_VERSION}"
    Goto InvalidDotNET
  ${EndIf}
  Pop $1
  Pop $0
  DetailPrint ".NET Framework Version found: $0, matches required version: ${DOTNET_VERSION}."
  Goto ValidDotNET
 
InvalidDotNET:
  ${If} $0 == "not found"
    MessageBox MB_YESNO|MB_ICONEXCLAMATION \
    ".NET Framework not installed.$\nRequired Version: ${DOTNET_VERSION} or greater.$\nWould you like the installer to download the latest .NET Framework version from www.microsoft.com?" \
    IDYES Download IDNO ValidDotNET  
  ${Else}
    MessageBox MB_YESNO|MB_ICONEXCLAMATION \
    "Your .NET Framework version: $0.$\nRequired Version: ${DOTNET_VERSION} or greater.$\nWould you like the installer to download the latest .NET Framework version from www.microsoft.com?" \
    IDYES Download IDNO ValidDotNET
  ${EndIf}
 
Download:
  DetailPrint "Beginning download of latest .NET Framework version."
  NSISDL::download ${DOTNET_URL} "$TEMP\dotnetfx.exe"
  DetailPrint "Completed download."
  Pop $R0
  StrCmp $R0 "success" +2
    Abort "Download failed: $R0"
  DetailPrint "Pausing installation while downloaded .NET Framework installer runs."
  ExecWait 'dotnetfx.exe /q /c:"install /q"'
  DetailPrint "Completed .NET Framework install/update. Cleaning temporary files..."
  Delete "$TEMP\dotnetfx.exe"
  DetailPrint "Completed cleaning temporary files."
 
ValidDotNET:
  DetailPrint "Proceeding with remainder of installation..."
!macroend