How to detect the installed version of .NET framework

Author: BitRock Support       Date: March 02, 2010 21:50       Tags: Windows

To detect if the the required .NET Framework version if installed in the target system, you just have to include the code below:

<setInstallerVariable name="required" value="3.5" />
<setInstallerVariable name="version" value="" />
<!-- .NET 1.0 -->
<actionGroup>
   <actionList>
       <registryGet name="3705" key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v1.0" variable="dotNetValue" />
        <setInstallerVariable name="version" value="1.0">
           <ruleList>
             <compareText text="${dotNetValue}" value="3321-3705" logic="equals" />
           </ruleList>
        </setInstallerVariable>
   </actionList>
   <ruleList>
      <compareVersions version1="${required}" version2="1.0" logic="less_or_equal" />
   </ruleList>
</actionGroup>

<!-- .NET 1.1 -->
<actionGroup>
   <actionList>
       <registryGet name="4322" key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v1.1" variable="dotNetValue" />
        <setInstallerVariable name="version" value="1.1">
           <ruleList>
             <compareText text="${dotNetValue}" value="3706-4322" logic="equals" />
           </ruleList>
        </setInstallerVariable>
   </actionList>
   <ruleList>
      <compareVersions version1="${required}" version2="1.1" logic="less_or_equal" />
   </ruleList>
</actionGroup>

<!-- .NET 2.0 -->
<actionGroup>
   <actionList>
       <registryGet name="50727" key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\policy\v2.0" variable="dotNetValue" />
        <setInstallerVariable name="version" value="2.0">
           <ruleList>
             <compareText text="${dotNetValue}" value="50727-50727" logic="equals" />
           </ruleList>
        </setInstallerVariable>
   </actionList>
   <ruleList>
      <compareVersions version1="${required}" version2="2.0" logic="less_or_equal" />
   </ruleList>
</actionGroup>

<!-- .NET 3.0 -->
<actionGroup>
   <actionList>
       <registryGet name="InstallSuccess" key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" variable="dotNetValue" />
        <setInstallerVariable name="version" value="3.0">
           <ruleList>
             <compareText text="${dotNetValue}" value="1" logic="equals" />
           </ruleList>
        </setInstallerVariable>
   </actionList>
   <ruleList>
      <compareVersions version1="${required}" version2="3.0" logic="less_or_equal" />
   </ruleList>
</actionGroup>

<!-- .NET 3.5 -->
<actionGroup>
   <actionList>
       <registryGet name="Install" key="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" variable="dotNetValue" />
        <setInstallerVariable name="version" value="3.5">
           <ruleList>
             <compareText text="${dotNetValue}" value="1" logic="equals" />
           </ruleList>
        </setInstallerVariable>
   </actionList>
   <ruleList>
      <compareVersions version1="${required}" version2="3.5" logic="less_or_equal" />
   </ruleList>
</actionGroup>

Depending on the requested version, the appropriate actionGroup will be evaluated. For example, if .NET 3.0 is required, version checks from 1.0 through 2.0 will be skipped (as it does not matter if the are installed). After the code is executed, you can just throw an error if no greater version was found (version is still ""):

<throwError text="This application requires .NET ${required} or greater">
    <ruleList>
      <compareText text="${version}" value="" logic="equals" />
   </ruleList>
</throwError>
    

 

Back You should login to comment

 

You are
currently not
logged in.

 Log in 

or

Sign up