Click here to Skip to main content
13,549,157 members
Click here to Skip to main content
Add your own
alternative version


41 bookmarked
Posted 13 Nov 2005

Installing .NET Framework 2.0 Applications with InstallShield

, 13 Nov 2005
Rate this:
Please Sign up or sign in to vote.
How to install .NET 2.0 Framework applications with InstallShield.


This article describes my attempts at deploying a .NET Framework 2.0 application using InstallShield X. I'm not really happy with the outcome, but hopefully it will help someone understand the issues and perhaps pave the way for something better.

InstallShield X provides a helpful deployment wizard that allows you to select the version of .NET Framework from a drop-down list box. This takes out of your hands all the messy business of detecting the .NET version on the target platform and installing the appropriate framework; you just make your selection and it's all done for you. Unfortunately, the list box doesn't support .NET v2.0 and after consulting the Macrovision website it became clear that there are no plans to address this issue in the near future; see this. It was for this reason that I decided to write this article.

The problem can be split into the following steps:

  1. Detecting whether the target platform has .NET v2.0 already installed.
  2. Checking that the target platform has the necessary software to support .NET v2.0.
  3. Installing the support software required by .NET 2.0 – as needed.
  4. Installing .NET 2.0 – as needed.
  5. Installing my application.

I found a program called DetectDotNet after searching CodeProject. This seemed to do most of what was required for the first step. However, it needed a bit of surgery before it could take the required .NET Framework as an input parameter and return a suitable exit code; see Listing 1. My plan was to create an InstallShield script and custom action that would launch DetectDotNet and run the necessary installation packages before continuing with the installation; see Listing 2. However, I ran into the following problems, which is why I'm not too happy with the overall result:

  1. InstallShield script doesn't recognize MS-DOS exit values so you have to run DetectDotNet from a batch file, test the %errorlevel% and then create a file for the InstallShield script to detect; see Listing 3.
  2. The .NET 2.0 Framework requires Windows Installer 3.0 (for NT), but unfortunately it doesn't seem that you can't install it from inside another installation program. I couldn't think of a way around this problem apart from writing a kind of bootstrap installer program. Ideas anyone?

The solution presented here doesn't check whether Windows Installer 3.0 has been installed on the target platform because I ran out of time. The best I can suggest for now is that you tell the user to install Windows Installer 3.0 before running your setup.exe (or App.msi). Installing this program multiple times doesn't seem to hurt.

The dependency on Windows Installer 3.0 (or 3.1) seems to imply that the only supported environments for .NET v2.0 are:

  • Windows 2000 sp3 and sp4
  • Windows Server 2003
  • Windows XP sp2

However, you can use Windows Installer 2.0 for non-NT platforms so this extends your reach to:

  • Windows 98
  • Windows 98 SE
  • Windows ME

[Thanks to David Kean for informing me about the above dependencies]. You can find the redistributables for Windows Installer 3.1 (WindowsInstaller-KB893803-v2-x86.exe) and .NET v2.0 Framework (dotnetfx.exe) in the Microsoft website.

I created the installation program and the script using InstallShield X, but other versions work in a similar fashion:

  1. Open the InstallShield IDE and create a new project in the usual way.
  2. Switch to the Installation Designer View and open the Behaviour and Logic folder.
  3. Click on 'Support Files' in the left view and right-click | Insert Files in the right view to add the files: detect.cmd, DetectDotNet.exe and dotnetfx.exe.
  4. Click on 'InstallScript' in the left view, select the 'Files' folder in the middle view and then right-click | New Script File. This opens a script template in the right view into which you should type Listing 2 as your custom function.
  5. Click on 'Custom Actions' in the left view, select the 'Custom Actions' item in the middle view and then right-click | Custom Action Wizard. Give your action a suitable name, select its type as 'Run InstallScript Code', select the name of your custom function as Source; see step 4, and use defaults for the remaining.
  6. Click on 'Sequences' in the left view and select the 'User Interface' item in the 'Installation' folder in the middle view. Right-click | Insert opens the Insert Action dialog where you will find your 'Custom Action' created in step 5. Select this item and press OK. Move your custom action until it is just after 'ISSetupFilesExact'.
  7. Run the Release Wizard (Build | Release Wizard) to create your installation.

Listing 1: MainDetectDotNet.cpp

//program takes an optional single parameter, 
//the version of CLR to find. The
//program returns 0 (success)if this version 
//of CLR is found, otherwise it
//returns -1 (fail). If no parameter is given 
//the program returns 0 (success).
// examples:
//  c:\>DetectDotNet 1.2.4455 //returns 0 if v 1.2.4455 is found
//  c:\>DetectDotNet 2.0*     //returns 0 if any v2.0 of CLR is found
//  c:\>DetectDotNet 1.*      //returns 0 if any v 1. of CLR is found
//  c:\>DetectDotNet *        //returns 0 if any version of CLR is found
//  c:\>DetectDotNet          //returns 0 whether CLR is found or not
int _tmain(int argc, _TCHAR* args[])        
    int rc = 0;                
    size_t matchLen = 0;        
    CDetectDotNet detect;

    if ( argc > 1 )    
        matchLen = _tcslen(args[1]);
        for ( size_t x = 0; x < matchLen; x++ )
            if ( args[1][x] == '*' )
                matchLen = x;
                args[1][x] = '\0';
        cout << "searching for v" << args[1] << endl;
        rc = -1;                                

    vector<STRING> CLRVersions;

       // cout lines ommitted for clarity

    for(vector<STRING>::iterator it = CLRVersions.begin(); 
        it < CLRVersions.end(); it++)
        cout << *it << endl;
        if ( rc == -1)                        
            if ((*it).compare(0,matchLen,args[1]) == 0)
                cout << "matching CLR found" << endl;
                rc = 0;
        return rc;                            

Listing 2: InstallShield script

#define CHECKPROGRAM   SUPPORTDIR^"Detect.cmd"
#define BOOTPROGRAM   SUPPORTDIR^"dotnetfx.exe"
#include "ifx.h"

export prototype DetectDotNet2(HWND);  

// Function:  MyFunction
//  Purpose:  This function will be called by the script engine when 
//            Windows(TM) Installer executes your custom action 
//            (see the "To Do," above).
function DetectDotNet2(hMSI)  
    STRING svResult;
    BOOL bExit, bLaunchAndWait;
  if (FindFile (SUPPORTDIR, "Found.txt", svResult) < 0) then

     AskOptions (EXCLUSIVE, ".NET Framework 2.0 Deployment",
                 "Install .NET Framework 2.0", bLaunchAndWait,
                 "Abort installation", bExit);

     if bExit  then
     if (LaunchAppAndWait(BOOTPROGRAM, "", LAAW_OPTION_WAIT) < 0) then       

Listing 3: Simple batch file

echo off
detectdotnet 2.*
if %errorlevel% EQU 0 (echo found > found.txt)



This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Will Stott
Web Developer
United Kingdom United Kingdom
A software developer

You may also be interested in...


Comments and Discussions

QuestionIS Express 11 Users - Are we screwed? Pin
JoeTwinstar18-Nov-05 21:16
memberJoeTwinstar18-Nov-05 21:16 
AnswerRe: IS Express 11 Users - Are we screwed? Pin
Will Stott18-Nov-05 22:20
memberWill Stott18-Nov-05 22:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02-2016 | 2.8.180515.1 | Last Updated 13 Nov 2005
Article Copyright 2005 by Will Stott
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid