Conditional compilation for .NET 4
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.
I think this is what you are looking for:
#if NET40
...
#elif NET35
...
#else NET20
...
#endif