在 Windows 8、Windows 10 桌面模式下的 .NET Framework 程序中,引用 Windows.Runtime 的 API。

参考:1、https://www.cnblogs.com/webtojs/p/9675956.html

   2、http://jennal.com/2016/04/28/using-windows-runtime-at-winform/

   3、https://software.intel.com/en-us/articles/using-winrt-apis-from-desktop-applications

   4、https://social.msdn.microsoft.com/Forums/windows/en-US/40b4f86d-b6d5-430e-a235-7fc003dec4c4/how-to-use-windowsdevicesgeolocation-api-in-a-c-winform-win32-desktop-application-in-windows-10

大概总结下,主要就是先编辑项目文件,添加一条属性:

<PropertyGroup>
  <TargetPlatformVersion>10.0</TargetPlatformVersion>
</PropertyGroup>

加完这条属性后,就可以在引用中,勾选 Universal Windows 的组件了。

不过这样发布出来的程序,也就仅限于指定的 TargetPlatform 了。

关于 await 报错,根据参考链接文章指出,需要引用:

C:Program Files (x86)Windows Kits10UnionMetadatawidows.winmd

但是目前在 Windows 10 17763.379 中测试,引用会发生冲突,暂无解决方案,只能暂时不用 await 关键词来等待异步返回了。

原文地址:https://www.cnblogs.com/xwgli/p/10547224.html