是否可以有条件地编译为 .NET Framework 版本? [英] Is it possible to conditionally compile to .NET Framework version?
问题描述
我记得在使用 MFC 时,您可以通过检查 _MFC_VER
宏来支持多个版本的 MFC 框架.
I can recall back when working with MFC you could support multiple versions of the MFC framework by checking the _MFC_VER
macro.
我现在正在使用 .NET 4 做一些事情,并希望在几个地方使用 Tuple,但仍然保持其他所有内容与 3.5 兼容.
I'm doing some stuff now with .NET 4 and would like to use Tuple in a couple of spots but still keep everything else 3.5 compatible.
我正在做类似的事情:
#if DOTNET4
public Tuple<TSource, TResult> SomeMethod<TSource, TResult>(){...}
#else
public KeyValuePair<TSource, TResult> SomeMethod<TSource, TResult>(){...}
#endif
推荐答案
没有可以使用的内置预编译器常量.但是,在 VS 中创建自己的构建配置很容易,每个配置都有自己的一组定义的常量,当然还有目标框架版本.很多人这样做是为了有条件地编译基于 32 位或 64 位差异的数据.
There are no builtin precompiler constants that you can use. But, it is easy enough create your own build configurations in VS with each configuration having its own set of defined constants and of course a target framework version. A lot of people do this to conditionally compile based 32 or 64 bit differences.
这篇关于是否可以有条件地编译为 .NET Framework 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!