5

I tried using Environment.Version.ToString() to determine what .NET framework on the target machine is in use, but it says I'm using .NET 2.0, when version 4.0 is installed.

How do I detect what version of the .NET Framework is running on the target machine?

George Stocker
  • 57,289
  • 29
  • 176
  • 237
Gilad Naaman
  • 6,390
  • 15
  • 52
  • 82
  • 2
    Chicken and egg. If your C# code runs then you already know you've got the .NET version that your code requires. – Hans Passant Dec 29 '10 at 17:52
  • I know I has .NET framework installed on my computer, but I want to know the version on the target computer (Making a simple installer for checking) – Gilad Naaman Dec 29 '10 at 17:54
  • Check this question http://stackoverflow.com/questions/199080/how-to-detect-what-net-framework-versions-and-service-packs-are-installed – RRUZ Dec 29 '10 at 17:56

2 Answers2

5

Environment.Version.ToString(); returns version of your application not system, you can read the version from registry or search in %windows%\Microsoft.NET\Framework folders to find maximum number.

The registry key is HKLM\Software\Microsoft\NET Framework Setup\NDP\ see How to detect what .NET Framework versions and service packs are installed?

Community
  • 1
  • 1
Saeed Amiri
  • 22,252
  • 5
  • 45
  • 83
1

To find out what versions of .NET are available on a machine, you need to look in the registry - see Determine which versions and service pack levels of .NET Framework are installed.
(Originally MSDN KB article 318785)

Brian Rogers
  • 125,747
  • 31
  • 299
  • 300
MarkXA
  • 4,294
  • 20
  • 22