Detecting .NET Framework versions with WiX

How to use WixNetfxExtension to detect .NET framework versions (including those higher than 4.6.2)


When building a Windows installer, it's often useful to be able to check whether the user's machine has the required version of the .NET Framework prior to installation.

In WiX, this can be achieved using the WixNetFxExtension.

Firstly, you'll need to add the WixNetFxExtension to your project by adding the following to your candle and light commands:

-ext WixNetFxExtensions

Then, you can use the various properties (described in the documentation I linked to earlier) to check for a version of the .NET Framework.

One common reason that installers would want to detect the .NET Framework version is to block the install unless the required framework version is installed.

Here's an example that blocks the install unless .NET 4.0 or greater is installed:

<PropertyRef Id='WIX_IS_NETFRAMEWORK_40_OR_LATER_INSTALLED'/>
<Condition Message='This setup requires the .NET Framework 4.0 (or greater) to be installed.'>
    <![CDATA[Installed OR WIX_IS_NETFRAMEWORK_40_OR_LATER_INSTALLED]]>
</Condition>

Here's an example that blocks the install unless .NET 4.6.2 or greater is installed:

<PropertyRef Id='WIX_IS_NETFRAMEWORK_462_OR_LATER_INSTALLED'/>
<Condition Message='This setup requires the .NET Framework 4.6.2 (or greater) to be installed.'>
    <![CDATA[Installed OR WIX_IS_NETFRAMEWORK_462_OR_LATER_INSTALLED]]>
</Condition>

Now, you may notice (at the time this article was published, at least) that there are no properties for .NET Framework 4.7 or above. This is unfortunate, but luckily there are workarounds! The WIXNETFX4RELEASEINSTALLED property returns the .NET release key. This is a unique number that identifies the .NET Framework value. More information about release keys is available from Microsoft's official documentation. We can instead use this WIXNETFX4RELEASEINSTALLED to check the release key to work out what version of the .NET Framework is installed.

Here's an example that blocks the install unless .NET 4.7.2 (release key 461808) or greater is installed:

<PropertyRef Id='WIXNETFX4RELEASEINSTALLED'/>
<Condition Message='This setup requires the .NET Framework 4.7.2 (or greater) to be installed.'>
    <![CDATA[Installed OR (WIXNETFX4RELEASEINSTALLED >= "#461808")]]>
</Condition>

I hope you find this information helpful.


Posted by Matthew King on 4 October 2019
Permission is granted to use all code snippets under CC BY-SA 3.0 (just like StackOverflow), or the MIT license - your choice!