开发者

What happened to the .NET version definition with v4.0?

开发者 https://www.devze.com 2022-12-22 08:34 出处:网络
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

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 开发者_JAVA技巧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?


The NET_x_y version number manafests you speak of were never part of an official spec, and it would appear Microsoft has discontinued them.


What's wrong with Environment.Version?


Assembly.ImageRuntimeVersion

contains which runtime version an assembly was compiled against, so there is no need for that ugly hack you are doing with the preprocessor directives at all.

0

精彩评论

暂无评论...
验证码 换一张
取 消