桌面 C# - 引用 Windows.Devices

mat*_*vzb 5 c# windows reference bluetooth-lowenergy windows-10-desktop

我正在尝试用 C# 为 Windows 10 创建一个经典的桌面应用程序,它将能够与 BLE 设备通信。我按照说明(适用于 Windows 桌面 C# 应用程序的蓝牙 4.0(低功耗)API)并将标签添加到项目文件中

<TargetPlatformVersion>10.0.10156</TargetPlatformVersion>
Run Code Online (Sandbox Code Playgroud)

并重新加载项目。我只能访问 Windows 命名空间:引用对话框

我不知道我在其中一项测试中做了什么,但是一旦该列表填充了大量其他命名空间,我就可以检查 Windows.Devices 命名空间,这对我的项目至关重要。我现在可以通过最近选项添加 Windows.Devices,但不能添加任何其他命名空间...

你们知道我应该怎么做才能访问所有 Windows.xy 命名空间的列表吗?

Car*_*sen 5

要从Windows.Devices.NET Framework 代码访问和其他 WinRT API,

  1. 将 NuGet 包添加Microsoft.Windows.SDK.Contracts到项目中
  2. 配置项目以支持包引用(右键单击packages.config,选择 Migrate packages.config to PackageReference...)


gli*_*ihm 3

来自OP作者的评论:

更新 - 我创建了一个新项目并添加了 C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd 和 C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5 \System.Runtime.WindowsRuntime.dll 允许我包含 Windows.Devices 命名空间,而无需在“引用”对话框中选择 Windows.Device。

这对我们每个人都有效。