What happened to the .NET version definition with v4.0?
Posted
by Tom Tresansky
on Stack Overflow
See other posts from Stack Overflow
or by Tom Tresansky
Published on 2010-03-07T17:18:34Z
Indexed on
2010/04/26
13:33 UTC
Read the original article
Hit count: 301
I'm building a C# class library, and using the beta 2 of Visual Web Developer/Visual C# 2010. I'm trying to save information about what version of .NET the library was built under. In the past, I was able to use this:
// What version of .net was it built under?
#if NET_1_0
public const string NETFrameworkVersion = ".NET 1.0";
#elif NET_1_1
public const string NETFrameworkVersion = ".NET 1.1";
#elif NET_2_0
public const string NETFrameworkVersion = ".NET 2.0";
#elif NET_3_5
public const string NETFrameworkVersion = ".NET 3.5";
#else
public const string NETFrameworkVersion = ".NET version unknown";
#endif
So I figured I could just add:
#elif NET_4_0
public const string NETFrameworkVersion = ".NET 4.0";
Now, in Project->Properties, my target Framework is ".NET Framework 4". If I check:
Assembly.GetExecutingAssembly().ImageRuntimeVersion
I can see my runtime version is v4.0.21006 (so I know I have .NET 4.0 installed on my CPU). I naturally expect to see that my NETFrameworkVersion variable holds ".NET 4.0". It does not. It holds ".NET version unknown".
So my question is, why is NET_4_0 not defined? Did the naming convention change? Is there some simple other way to determine .NET framework build version in versions > 3.5?
© Stack Overflow or respective owner