I have a bunch of unit tests that need to be conditional compiled based on Windows OS version. This unit tests are testing TxF that is only available in Windows Vista and above.
#if WIN_OS_VERSION >= 6.0
// Run unit tests
#endif
I don't think there's a way to conditionally compile code based on OS version. The documentation for #define states (emphasis mine):
Symbols can be used to specify conditions for compilation. You can test for the symbol with either #if or #elif. You can also use the conditional attribute to perform conditional compilation.
You can define a symbol, but you cannot assign a value to a symbol. The #define directive must appear in the file before you use any instructions that are not also directives.
You can also define a symbol with the /define compiler option. You can undefine a symbol with #undef.
A symbol that you define with /define or with #define does not conflict with a variable of the same name. That is, a variable name should not be passed to a preprocessor directive and a symbol can only be evaluated by a preprocessor directive.
The scope of a symbol created by using #define is the file in which it was defined.
You will have to conditionally run it instead:
void TestTxF() {
if (System.Environment.OSVersion.Version.Major < 6) {
// "pass" your test
}
else {
// run it
}
}
Update:
This has been asked before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With