MAKEMSI quickly and reliably creates MSI files in a non-programmatic way
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
[Bottom][Contents][Prev]: Launch Conditions[Next]: IIS Installed?
Have your say! Join the MAKEMSI discussion list or view archive! Suggest improvements. No question too simple or too complex.
\->Tips and Tricks->Launch Conditions->.NET Framework Installed?

Launch Condition: .NET Framework Installed?

You can use the "MsiNetAssemblySupport" property but it has issues so you may need to do your own dot net framework detection as shown below.

It sounds like Microsoft really excelled this time by making it nearly impossible to detect their frameworks (even they fail).

Here are some of the external links documenting some of the possible detection mechanisms (sounds like all approaches involve crossing your fingers) and even needs to be aware of the OS in use!

The following macro checks for the a specific dotnet framework by looking at the the registry value "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v{{version}}\Version" (hopefully it works more often than it fails):

;----------------------------------------------------------------------------
;--- Reusable macro to check for ".net" versions (version 09.321) -----------
;----------------------------------------------------------------------------
#(
    ;--- http://msdn.microsoft.com/en-us/kb/kb00318785.aspx -----------------
    #define CheckFor.NET

    ;--- Validate Passed parameters -----------------------------------------
    {$!:Version,Property}

    ;--- User passes a version number ("1.1" etc) ---------------------------
    #ifndef RegVer.NetVersion={$Version}
        #error ^Sorry but the "{$Version} of .NET version is unknown (so we can't test for it).^
    #endif

    ;--- Want to check for .NET only or check and abort? --------------------
    #if ['{$PROPERTY=^^}' = '']
        ;--- No property defined so user wants to abort if missing ----------
        #define+ @@.NetAbort    Y
        #define+ @@MsiProperty  DOTNET_{$Version}_INSTALLED
    #elseif
        ;--- Would only define property if we don't want to abort when missing ---
        #define+ @@.NetAbort    N
        #define+ @@MsiProperty  {$PROPERTY=^^}
    #endif

    ;--- Look for a registry value related to the version -------------------
    #(
        <$RegistryRead
             Property="<$@@MsiProperty>"
                 HKEY="LOCAL_MACHINE"
                  KEY="SOFTWARE\Microsoft\NET Framework Setup\NDP\v<$RegVer.NetVersion={$Version}>"
                 NAME="Version"
            Condition="not Installed"
             Validate="N"               ;;Will validate below if we wish...
        >
    #)

    ;--- Now abort if we want to AND need to --------------------------------
    #if ['<$@@.NetAbort>' = 'Y']
    #(
        ;--- Abort if the property doesn't exist "version" couldn't be found ---
        <$AbortIf
            condition=^not <$@@MsiProperty>^
              Message=^The install of "<$ProdInfo.ProductName>"
                       version <$ProductVersion> can't continue as it
                       requires .NET version {$Version} (which is not installed).
                       You can obtain freely
                       obtained this from Microsoft's site.^
                  Seq="AppSearch-"
                  SeqTable="InstallUISequence InstallExecuteSequence"
        >
    #)
    #endif
#)

;--- Map user friendly name to what exists under registry (2.0 => 2.0.50727 etc) ---
#define RegVer.NetVersion=1.1           1.1.4322
#define RegVer.NetVersion=1.1.4322      1.1.4322
#define RegVer.NetVersion=2.0           2.0.50727
#define RegVer.NetVersion=2.0.50727     2.0.50727
#define RegVer.NetVersion=3.0           3.0
#define RegVer.NetVersion=3.5           3.5

The above macro works in two modes, if the "PROPERTY" parameter is supplied it looks for the framework but doesn't abort if missing, otherwise it will abort if its not installed! If you know of a better way of doing this please let me know...

This is an example of it checking for version dot net 3.5 and aborting if its not installed:

<$CheckFor.NET Version="3.5">

This is an example of only checking for the framework and on completion if the framework exists the property will exist (and contain the full version number):

<$CheckFor.NET Version="3.0" Property="HAVE_DOT_NET_3.0">
<$CheckFor.NET Version="3.5" Property="HAVE_DOT_NET_3.5">

In the above you are only checking but if you needed one or the other framework you would be able to abort by examination of the returned properties.


Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.Please email me any feedback, additional information or corrections.
See this page online (look for updates)

[Top][Contents][Prev]: Launch Conditions[Next]: IIS Installed?


MAKEMSI© is (C)opyright Dennis Bareis 2003-2008 (All rights reserved).
Saturday May 28 2022 at 3:11pm
Visit MAKEMSI's Home Page
Microsoft awarded me an MVP (Most Valuable Professional award) in 2004, 2005, 2006, 2007, 2008 & 2009 for the Windows SDK (Windows Installer) area.