C# Conditional Compilation and framework targets
- by McKAMEY
There are a few minor places where code for my project may be able to be drastically improved if the target framework were a newer version. I'd like to be able to better leverage conditional compilation in C# to switch these as needed.
Something like:
#if NET_40
using FooXX = Foo40;
#elif NET_35
using FooXX = Foo35;
#else
using FooXX = Foo20;
#endif
Do these symbols come for free? Do I need to inject these symbols as part of the project configuration? Seems easy enough to do since I'll know which framework is being targeted from msbuild.
I think I've seen that NET_40 symbol isn't defined? If so I think I could do this?
#if !NET_35 && !NET_20
#define NET_40
#endif
Or do I need to define it in the msbuild command:
/p:DefineConstants="NET_40"