Simple Way To Install .NET Framework

From NSIS Wiki
Jump to navigationJump to search

Information

After looking at the other examples of how to detect the current Microsoft .NET Framework on the computer, they all don't seem to be looking in the right place. If you do a search on the MSDN website you will see that it has some documentation on how to see if a version of the .NET framework is installed.

How To Use

First copy the script into your NSIS script. Using the list below, change NETVersion to the right version and download the installer:

.NET Version Download Link
1.0.3705 http://www.filehippo.com/download_dotnet_framework_1/
1.1.4322 http://www.filehippo.com/download_dotnet_framework_1/
2.0.50727 http://www.filehippo.com/download_dotnet_framework_2/
3.0 http://www.filehippo.com/download_dotnet_framework_3/3481/
3.5 http://www.filehippo.com/download_dotnet_framework_3/
4.0.30319 http://www.microsoft.com/download/en/details.aspx?id=17718

Then move the .NET installer to the folder with NSIS and change NETInstaller to the filename. Compile your script and test it, if you have the framework installed then it wont install and if it isnt, then it will install.

Example Section

!define NETVersion "3.5"
!define NETInstaller "dotNetFx35setup.exe"
Section "MS .NET Framework v${NETVersion}" SecFramework
  IfFileExists "$WINDIR\Microsoft.NET\Framework\v${NETVersion}" NETFrameworkInstalled 0
  File /oname=$TEMP\${NETInstaller} ${NETInstaller}
 
  DetailPrint "Starting Microsoft .NET Framework v${NETVersion} Setup..."
  ExecWait "$TEMP\${NETInstaller}"
  Return
 
  NETFrameworkInstalled:
  DetailPrint "Microsoft .NET Framework is already installed!"
 
SectionEnd

Reference

How to determine which versions of the .NET Framework are installed and whether service packs have been applied