如何在 uwp 中为特定 sdk 定义条件编译器符号 [英] How to define conditional compiler symbols for specific sdk in uwp

查看:21
本文介绍了如何在 uwp 中为特定 sdk 定义条件编译器符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Visual Studio 2015中编写一个UWP应用程序.最小sdk是10240.最大是14393.我想写sdk特定的代码,所以我想定义一个条件编译符号.我可以简单地在构建选项卡下的项目属性窗口中定义它.但是我可以在哪里定义条件?

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?

我想要存档的就是这个.我在构建选项卡SDK_14393"中定义了一个符号.然后我有一些这样的代码,我只想在 14393 sdk 中执行,

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

但即使我在不​​同的 sdk 中,它也会一直执行.所以我的问题是如何正确存档?

But it executes all the time even when I'm in a different sdk. So my question is how to archive this correctly?

推荐答案

#ifdef 不是构建自适应代码的正确工具,因为您需要发布应用程序的两个版本.并且操作系统版本号/SDK 版本不是一个很好的鉴别器.

#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.

如果您正在调用 WinRT API,请使用 ApiInformation 键入以查看您想要的功能在运行时是否可用.如果您正在调用 Win32,则使用延迟加载和 QueryOptionalDelayLoadedAPI 函数.

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.

这篇关于如何在 uwp 中为特定 sdk 定义条件编译器符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆