Are there any predefined constants in the C# compiler to detect what version of the platform is being targeted?
I can set a platform in Project options but how can I write single source for .NET 2 and .NET 3.5 ?
Edit: I really want to write some code once and be able to switch behavior with something like #if CLR_VERSION35 and then rn different configurations.
The reverse question: If I make CLR35 and CLR20 configurations is it possible to select target platform based on this? The option is not available in VS2008 and I don't know a lot about MSBUILD yet.
.NET Framework 3.5 is a superset of 2.0 so all 2.0 apps should run on 3.5 without modification. As it is a superset there's no way of back-peddling to not use 3.5 functionality if your app finds itself on 2.0, not that makes sense anyway.
If you need to target 2.0 and you can write what you need in 2.0 then that's the way to go, 3.5 will still run your app fine. Effectively, you have to write for the lowest common denominator or include the 3.5 runtime redistributables with your installer to ensure that your customer has the correct environment for your app.