问题
I'm writing a UWP app in Visual Studio 2015. Minimum sdk is 10240. Maximum is 14393. I want to write sdk specific code, so I want to define a conditional compilation symbol. I can simply define it in the project properties window under build tab. But where I can define the condition?
Simply what I want to archive is this. I have define a symbol in build tab 'SDK_14393'.. then I have some code like this which I want to execute only in 14393 sdk,
#if SDK_14393
//some code here
#endif
But it executes all the time even when I'm in a different sdk. So my question is how to archive this correctly?
回答1:
#ifdef
is not the right tool to build adaptive code, because you'll need to ship two versions of your app. And the OS version number / SDK version is not a good discriminator.
If you're calling WinRT APIs, use the ApiInformation type to see if the feature you want is available at runtime. If you're calling Win32 then use delayload and the QueryOptionalDelayLoadedAPI function.
来源:https://stackoverflow.com/questions/40434424/how-to-define-conditional-compiler-symbols-for-specific-sdk-in-uwp