.NET 4的条件编译 [英] Conditional compilation for .NET 4

查看:108
本文介绍了.NET 4的条件编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

有条件的编译和框架目标

我有一些适用于.NET 4的代码,但不适用于.NET  3.5。在.NET  3.5中,它需要使用对Windows的互操作调用。

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.

在两种情况下,我都希望使用 ifdef来使用不同的代码路径(最终,我会

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

是否存在预定义的指令值来标识何时使用.NET  4编译代码?

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

是否与所有预定义指令( DEBUG TRACE 等)?下面的页面仅提供指令,而不提供标准的预定义值:

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#预处理程序指令

推荐答案

编译器不知道任何特定的.NET Framework版本。它所看到的只是参考程序集。也不能保证您的程序将与您所针对的.NET版本一起运行。即使您是为2.0构建的,也可以使用.NET 4.0 CLR运行。

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.

使用 Environment.Version

这篇关于.NET 4的条件编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆