How to define conditional compiler symbols for specific sdk in uwp

不想你离开。 提交于 2021-02-05 11:26:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!