One option is to detect 4.0 using the version string:
Environment.Version.CompareTo(new Version(4, 0));
then since 2.0 and 2.5 share a CLR version number, these need to be distenguished by checking the registry. Since those versions are released already, the strings to look for are known.