Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio
All postings are provided AS IS
with no warranties, and confer no rights. Additionally, views expressed
herein are my own and not those of my employer, Microsoft.
I previously posted some sample code to detect the version(s) and service pack levels of the .NET Framework that are installed on a computer (here and here). The original version of the sample code that I wrote queries the officially documented registry values that are used to detect the presence of each specific version of the .NET Framework.
Since I posted this sample code, I have heard feedback from some customers who are including the .NET Framework as part of their setup packages. They indicated that sometimes this code reports false positives - in other words, the sample returns true for a specific version of the .NET Framework but it isn't actually installed on the system. I have seen this a couple of times in the past as well, and the root cause was that some of the registry entries used to detect the .NET Framework were orphaned on the system after an uninstall or OS reinstall scenario.
In order to help address this type of issue, I've created a new version of the sample code that adds some new checks to help guard against orphaned registry values. The logic it uses is to query the registry values like the previous sample used to, and then to supplement that with an additional check that loads mscoree.dll and uses some of its APIs to query for the presence of specific versions of the .NET Framework. The underlying algorithm for this mscoree.dll-based check came from Junfeng Zhang and from a sample published on MSDN.
This algorithm should prove more reliable in detecting whether or not a specific version of the .NET Framework is installed on the system because it does not rely solely on the registry. In addition, it provides the side benefit of performing a quick health check for the .NET Framework itself because it attempts to invoke some APIs in the runtime.
The new sample code contains the following specific changes from the previous version that I published:
You will need the following in order to compile this sample:
Please let me know if you have any trouble building or running this sample or incorporating it into your product setup logic.
<update date="5/29/2009"> Fixed broken link to the sample code. </update>
Thanks for the src!
http://www.asoft.be also has a nice one that I use and it's kept uptodate.
There is no source but it's the one that I package to customers.
It's called .NET version detector.
Hey Oliver, thanks for the post. It was most helpful.
The links for the "new sample code" seem to be broken.. :(
Hi George - The links appear to be working fine for me. What error do you see when you try to click on the links?
The GetRequestedRuuntimeInfo API has been deprecated in the .NET Framework 4