开发者

Conditional compilation for .NET 4 [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Conditional compilation and framework targets

I have some code that works in .NET 开发者_如何转开发4, but it does not work in .NET 3.5. In .NET 3.5 it requires to use interop calls to Windows.

I would like using a "ifdef" to use a different code path in both cases (eventually I will deprecate the .NET 3.5 code).

Is there a pre-defined directive value to identify when the code is compiled with .NET 4?

Is there a good link with all the predefined directives (DEBUG, TRACE, etc.)? The page below only gives the directives, but not the standard predefined values:

C# Preprocessor Directives


I think this is what you are looking for:

#if NET40   
...  
#elif NET35  
...  
#else NET20  
...  
#endif  


The compiler isn't aware of any particular .NET Framework version. All it sees is the reference assemblies. Nor is there any guarantee that your program will run with the .NET version that you target. It is quite possible to run with the .NET 4.0 CLR even if you built for 2.0.

Use Environment.Version instead.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜