Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect .NET 4.5.1 and future backwards-compatible releases

Per the guidance laid out in the MSDN article How to: Determine Which .NET Framework Versions Are Installed I have coded a WiX installer to check the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Release registry key to determine that .NET 4.5.1 is installed, and use that detection to set a prerequisite.

The problem I've run into now, is when .NET 4.5.2 is installed, that same key is no longer 378675 or 378758, but is now 379893. .NET 4.5.2 is supposed to be a "highly compatible, in-place update", yet the recommended version-checking algorithm is not backwards-compatible.

Checks for prior versions didn't have this issue, the 2.0, 3.0 and 3.5 registry keys are all still present even if a later version is installed. e.g. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Version is still present even if 3.5 is installed.

So previously, the Microsoft-recommended version detection method was forwards-compatible, but that's no longer the case with 4.5 / 4.5.1 / 4.5.2. What then, should I be doing instead? I'm loathe to just add 379893 (.NET 4.5.2) to the set of registry values I check for, since that will presumably fail when (if) .NET 4.5.3 (or other) is released. Maybe I could check HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Version for >= 4.5.51641, but that's not the recommended approach according to MSDN, and what happens if they release, say, 4.6 which is somehow not backwards-compatible?

like image 415
Snixtor Avatar asked Aug 12 '14 06:08

Snixtor


People also ask

Which version of the NET Framework is backward compatible?

Backward compatibility and the .NET Framework. The .NET Framework 4.5 and later versions are backward-compatible with apps that were built with earlier versions of the .NET Framework. In other words, apps and components built with previous versions will work without modification on the .NET Framework 4.5 and later versions.

What versions of the NET Framework are compatible with my application?

The .NET Framework 4.5 and later versions are backward-compatible with apps that were built with earlier versions of the .NET Framework. In other words, apps and components built with previous versions will work without modification on the .NET Framework 4.5 and later versions.

What is backward compatibility?

Backward compatibility means that an app that was developed for a particular version of a platform will run on later versions of that platform. .

Will my code run on a later version of NET Core?

Along with compatibility across .NET implementations, developers expect a high level of compatibility across versions of a given implementation of .NET. In particular, code written for an earlier version of .NET Core should run seamlessly on .NET 5 or a later version.


1 Answers

To find .NET Framework versions by querying the registry in code (.NET Framework 4.5 and later) states:

Check the value of the Release keyword to determine the installed version. To be forward-compatible, you can check for a value greater than or equal to the values listed in the table.

That was just slightly below where the MSDN link in the original question pointed (thanks for getting me close).

In my .wxs file, I have code that appears to work, failing with a valid message on too-low .Net 4.5 version.

Place the following property reference and condition in <Product>:

<!-- Must have at least .Net 4.5.2 which has release 379893 -->
<PropertyRef Id="NETFRAMEWORK45RELEASE"/>
<Condition Message="$(var.ProductName) requires .NET Framwork 4.5.2. Please install the .NET Framwork then run this installer again.">
    Installed OR ( NETFRAMEWORK45RELEASE AND NETFRAMEWORK45RELEASE >= "#379893" )
</Condition>

With the following fragment declared elsewhere:

<Fragment>
    <Property Id="NETFRAMEWORK45RELEASE">
        <RegistrySearch Id="NetFramework452Release"
                        Root="HKLM"
                        Key="Software\Microsoft\NET Framework Setup\NDP\v4\Full"
                        Name="Release"
                        Type="raw" />
    </Property>
</Fragment>
like image 195
mheyman Avatar answered Oct 12 '22 09:10

mheyman