Reputation: 85
What I need to detect if .net framework 4.5.X is installed on the current OS?.
I tried this but seems to be limited to framework 4.0 using a non-official update.
Upvotes: 0
Views: 2506
Reputation: 3497
// Checking the version using >= will enable forward compatibility,
// however you should always compile your code on newer versions of
// the framework to ensure your app works the same.
private static string CheckFor45DotVersion(int releaseKey)
{
if (releaseKey >= 393295) {
return "4.6 or later";
}
if ((releaseKey >= 379893)) {
return "4.5.2 or later";
}
if ((releaseKey >= 378675)) {
return "4.5.1 or later";
}
if ((releaseKey >= 378389)) {
return "4.5 or later";
}
// This line should never execute. A non-null release key should mean
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
private static void Get45or451FromRegistry()
{
using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) {
if (ndpKey != null && ndpKey.GetValue("Release") != null) {
Console.WriteLine("Version: " + CheckFor45DotVersion((int) ndpKey.GetValue("Release")));
}
else {
Console.WriteLine("Version 4.5 or later is not detected.");
}
}
}
Upvotes: 0
Reputation: 119
You can look in the registry or simply check in your installed programs. On Start menu type "appwiz.cpl", then search for .net You will see all of the .net installed on your machine.
Upvotes: 2
Reputation: 183
Just did your googling for you and found the following MSDN article directly referring to your question. Includes examples for version 4.5 and later...
https://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx
Upvotes: 3