3

The code:

Console.WriteLine(Environment.Version);

returns identical results (2.0.50727.5448) for .NET Framework 2.0, 3.0, and 3.5 SP1. How do I learn the exact version of the installed .NET platform?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Andrey Bushman
  • 11,712
  • 17
  • 87
  • 182

3 Answers3

4
System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion()
Bali C
  • 30,582
  • 35
  • 123
  • 152
Dave Bish
  • 19,263
  • 7
  • 46
  • 63
  • 2
    no, it is the wrong response. In this case I receive it (for all): v2.0.50727 – Andrey Bushman Apr 20 '12 at 15:46
  • @Bush: are you sure your code doesn't actually run on 2.0.50727? You can check this by examining the loaded dlls at runtime. – Vlad Apr 20 '12 at 15:47
  • @Vlad: In the MS Visual Studio project I change a target platform for 2.0, 3.0, 3.5 SP1 and I receive the same value for both specified above code options. – Andrey Bushman Apr 20 '12 at 15:50
4

You need to read registry keys to detect versions at service pack granularity. This article explains what key/value pairs you need to look for.

For example, you can tell 3.5 from 3.5 SP1 by looking at values inside

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5

"plain" 3.5 has Install = 1, while SP1 has SP >=1.

Scroll to the bottom of the article at the link to see the entire table.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
4

2.0, 3,0, 3,5 and 3.5SPx all based on the same set of core 2.0 libraries. Essentially all of these versions are 2.0 plus additional components. This answer contains the list of versions: How do the .NET Framework, CLR and Visual Studio version numbers relate to each other? and related information.

So when you ask what run-time environment version is you'll get 2.0 (the other variants are 1, 1.1 and 4.0 as far as I know).

If you need 3/3.5/SP distinction @dasblinkenlight gave you an answer. Otherwise explain what you trying to do to get more suggestions.

Community
  • 1
  • 1
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179