You can check for .Net as a requirement on the System Requirements project page. However, this merely prevents installation if .Net is not present. To install the .Net runtime if it isn't there yet requires a custom action. The general approach is as follows:
For .Net 2.0 there is an additional twist: it requires MSI 3.0 or later to be present on the target system, and also Administrator rights during installation. To cater for all possibilities, therefore, your installer must also check the installed MSI version and if necessary, install MSI 3.0 or later as well before installing the .Net runtime.
Tip: If you do include the (rather large) .Net redistributable in your project, then you might want to set the Compressor field of your build configuration to Deflate (fast). This does not compress the installation files as well as the deafult LZMA compression, but since the installer size is dominated by the already compressed .Net redistributable, the practical effect is very small. Deflate compression is a lot faster than LZMA compression and will reduce the build time substantially.
Although .Net applications are platform-independent (up to a point), the .Net and MSI redistributables are not. There are three cases of 32/64-bit systems:
The sample below uses the x86 (32-bit) versions of all redistributables. If you must support x64 Windows versions, then you must replace them with the appropriate x64 counterparts. Contact support@tarma.com if you need help with this.
We have a sample project that illustrates all that:
http://www.tarma.com/download/DotNetSample.zip (24 MB)
This download includes the .Net 2.0 and the MSI 3.0 installers as well. The salient points are:
Note: You must use ExpertInstall version 3.6.2793 or later for this sample. If necessary, download and install the latest ExpertInstall release first.
This is a Message Box action that displays a termination message if a .Net (and possibly MSI) installation are required but the installing user does not have Administrator rights. This is accomplished by using the following Condition:
(VersionCLR < 2000) AND NOT AdminUser
With this condition, the Message Box action is only executed if an older version than .Net 2.0 (or no version at all) is present on the target system and the user does not have Administrator rights (see the VersionCLR and AdminUser documentation for the details).
Furthermore, the Message Box action's Fail mode is set to Fail if run, which means that the installation is terminated if this action is executed.
Note: We could have required Administrator rights in the Installation level field on the Installer Options project page, but most installs don't require this and we want to limit the number of Administrator installs to the minimum necessary.
This is a Run Program action that runs the MSI 3.0 installer if VersionMsi is less than 3.0. (Note that the VersionMsi variable uses a dotted version syntax, hence the use of the $vercmp runtime function.) The action is run with the /norestart Arguments to prevent system reboots.
The InstallMSI action runs the MSI installer in interactive mode. This requires users to click additional buttons, such as Next and Finish. They must also acknowledge Microsoft license agreements. If you want to use hidden installation of the MSI runtime, then change the Arguments field to /norestart /quiet. However, the installation may take some time and the main installer cannot show any progress during that time.
Another Run Program action that runs the .Net 2.0 installer if the installed version is less than 2.0. The action is run with the /q Arguments; this makes the initial extraction silent, but still requires users to click additional buttons, such as Next and Finish. They must also acknowledge Microsoft license agreements. If you want to use a hidden installation, then change the Arguments field to /q:a /C:"Install /Q" (make sure to include the quotes exactly as shown). However, the .Net installation process potentially takes a long time and the main installer cannot show any progress during that time, which may lead users to believe that the installation "hangs".
A Message Box action that displays an error message if the preceding .Net installation failed. Note that the Condition:
(VersionCLR < 2000) AND LastExitCode AND (LastExitCode <> 8192) AND (LastExitCode <> 3010)
...causes this action only to be executed if a .Net install took place, and if the installation result (available through the LastExitCode variable) indicated a genuine problem. See below for information about the .Net installer's exit codes.
The Message Box action's Fail mode is set to Fail if run, which means that the installation is terminated if this action is executed. In that case, any partial installation will be rolled back automatically.
A Set Variable action that sets the TsuRebootRequired variable to nonzero if the .Net installer's exit code indicated that a system reboot is necessary. This in turn causes the main installer to prompt for a reboot at the end of the overall installation.
You must obtain the required .Net redistributables from Microsoft. We recommend the following web pages (note that Microsoft frequently changes its web site, so if the links below don't work, then try searching for .Net framework redistributable).
IMPORTANT: Different versions of the .Net redistributables have different system requirements and MSI requirements. Make sure that you thoroughly check all these before deploying your own installer.
.Net 2.0 redistributable for x86
.Net 2.0 redistributable for x64
.Net 3.0 redistributable for x86
.Net 3.0 redistributable for x64
.NET Framework 2.0 Deployment Guide (contains links to further information)
Microsoft .NET Framework 3.0 Deployment Guide (contains links to further information)
You must obtain the required Windows Installer redistributables from Microsoft. We recommend the following web pages (note that Microsoft frequently changes its web site, so if the links below don't work, then try searching for Windows Installer redistributable downloads).
Windows Installer Redistributables (for 3.0 and 3.1)