You’ll have to maintain two different versions. You can’t compile one XAP that supports both versions at the same time.
The Mango APIs are only available when compiling with the 7.1 SDK. And as such, you can’t do in-line checking in the code.
But it’s rather pointless, as there’s almost no users left that haven’t upgraded to Mango, and all new phones ship with Mango.