Detect .NET Framework 4.5.1 using WiX

10,185

You're including that # in the comparison, that's not going to help. Have you tried including the # in your CDATA comparison?

I would assume that when Microsoft people post code examples to detect framework versions it can't be done with a simple RegistrySearch in an MSI file.

http://blogs.msdn.com/b/astebner/archive/2013/10/17/10457758.aspx

Share:
10,185
Avery
Author by

Avery

Updated on June 23, 2022

Comments

  • Avery
    Avery almost 2 years

    I'm creating an installer project in my solution using WiX 3.8. As part of this install I create some launch conditions, one of which is checking that Microsoft .NET Framework 4.5.1 is installed.

    To do this I want to use some of the properties in the WixNetFxExtension lib which seem to work fine for older versions of the .NET framework. There is an example of how to do this on http://wixtoolset.org/documentation/manual/v3/howtos/redistributables_and_install_checks/check_for_dotnet.html This doesn't work for .NET 4.5.1 however as there is no NETFRAMEWORK451 property to check.

    Looking at the source for the NetFx451.wxs module (http://wix.codeplex.com/SourceControl/latest#src/ext/NetFxExtension/wixlib/NetFx451.wxs) it appears that there is no separate property to use for .NET 4.5.1, but rather it also uses the same NETFRAMEWORK45. As I understand it, v4.5.1 is an in-place upgrade for v4.5, so it uses the same registry keys (I think). Anyway, in that module, they simply check the version number returned from NETFRAMEWORK45 as follows:

    DetectCondition="NETFRAMEWORK45 >= $(var.NetFx451MinRelease)"
    

    So I assumed that I could just write a condition like the following:

        <PropertyRef Id="NETFRAMEWORK45" />
        <Condition Message="The .NET Framework 4.5.1 was not found.  Stopping installation.">
           <![CDATA[Installed OR (NETFRAMEWORK45 >= 378675)]]>
        </Condition>
    

    But, this returned the error message on a machine that I know has the .NET Framework 4.5.1 installed. So I created a condition like this so I could just see the version number being returned from the registry:

        <PropertyRef Id="NETFRAMEWORK45" />
        <Condition Message ="[NETFRAMEWORK45]">0</Condition>
    

    This shows a message box with the following text: #378758 So I know that the value in the registry is correct.

    So I am a bit confused why my condition failed. Is there something obvious I am missing here, or is there some other way to compare that value in the condition element?

    Here is the fix to include the hash symbol as suggested by PhilDW:

        <PropertyRef Id="NETFRAMEWORK45" />
        <Condition Message="The .NET Framework 4.5.1 was not found.  Stopping installation.">
          <![CDATA[Installed OR (NETFRAMEWORK45 >= "#378675")]]>
        </Condition>
    
    • Avery
      Avery about 10 years
      Edited to show fix as suggested by PhilDW. Note also that I had to include quotes around the value. Thanks for the help Phil.
    • Christian Maslen
      Christian Maslen over 9 years
      It's worth noting that the above comparison is comparing strings, so #900 will come up as higher than #378675. I'd say its a fair bet there won't be a point release of .NET 4.5 that will cause the release attribute in the registry to clock over to 1000000. For what it's worth I went with the assumption that any other number apart from the base release number is a higher point release and therefore what we want. So my comparison is: <![CDATA[Installed OR (NETFRAMEWORK45 AND NETFRAMEWORK45 <> "#378389")]]>
    • MichaC
      MichaC over 8 years
      The latest version of WiX has a property: WIX_IS_NETFRAMEWORK_451_OR_LATER_INSTALLED described here: wixtoolset.org/documentation/manual/v3/customactions/…. I built an MSI that used that property to see how WiX sets it, and it uses the fix described above exactly.
  • Mark Bailey
    Mark Bailey about 10 years
    I agree that the '#' symbol is probably causing the problem with your comparison, but it certainly strikes me as odd that this is included in the value for NETFRAMEWORK45. It's almost like they don't want you trying to make this kind of comparison...