【问题标题】:Detect whether project is being compiled for windows 8 or wp检测项目是否正在为 windows 8 或 wp 编译
【发布时间】:2012-09-25 05:27:31
【问题描述】:

我有一个 windows phone 应用程序,我正在尝试将它移植到 windows 8。问题是这些项目中应该有几个类是通用的。但是 windows phone 的某些功能在 windows 8 上不起作用,反之亦然。所以我可能应该使用预处理器指令来检测操作系统。是否有任何已经定义的预处理器常量可以帮助我解决这个问题?或者您能建议一些更好的方法吗?

附:这些类使用异步 ctp 库。其中一些还具有网络功能。由于 wp 和 win8 中的加载文件以不同的方式实现(我需要使用自定义标头和 POST 请求进行异步文件下载),因此我还必须考虑到这一点。

【问题讨论】:

    标签: c# windows-phone-7 windows-8 c-preprocessor


    【解决方案1】:

    您最好的选择是将所有通用代码放在Portable Library 中。这将允许您定位多个平台。

    我认为 Windows 8 没有预处理器指令,但您可以轻松地在构建配置中创建一个新指令(属性/条件编译符号)。

    【讨论】:

    • 还有其他方法吗?因为我使用的是可移植类库不支持的异步 ctp 库。
    • 没有。 Async CTP 为 Desktop、Phone、Silverlight 4 和 Silverlight 5 提供不同的 dll。Async 只是一种新语法。您可以对可移植库执行相同的操作。
    • 而且我似乎没有弄清楚:如何在 vs2010 中将 Async CTP 与可移植类库一起使用?编译时出现以下错误:The primary reference "AsyncCtpLibrary" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0 ..." which could not be resolved in the currently targeted framework. ".NETPortable,Version=v4.0,Profile=Profile104". To resolve this problem, either remove the reference "AsyncCtpLibrary" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0...".
    猜你喜欢
    • 2012-01-29
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2015-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-10
    相关资源
    最近更新 更多