c# - 使用 CSWinRT 调用 .net5 windows api

标签 c# wpf bluetooth windows-runtime

我在使用 .net 5.0 框架的 WPF 应用程序中使用 Windows.Devices.Bluetooth 库。 我通过安装 CSWinRT nuget 并在我的 csproj 文件中使用目标框架名字对象来引用 Windows api,如下所示:

<TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>

这不是添加对 windows.winmd 和 windowsruntime.dll 的引用,就像您在 .net5 之前必须做的那样。我可以毫无问题地使用 Windows 库,但我也在使用由使用 .net 4.7.2 的不同项目制作的类库,它也引用/使用 Windows.Devices.Bluetooth 库,这就是我收到此错误的原因:

Severity Code Description Project File Line Suppression State Error CS0012 The type 'BluetoothLEDevice' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'. 128 Active

所以我可以直接访问库,但不能通过 dll。可能是 dll 使用不同的框架的问题?

有人知道怎么解决吗?

最佳答案

对此的解决方案是升级类库项目 .net 5,以便两个项目都使用相同的框架。

关于c# - 使用 CSWinRT 调用 .net5 windows api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67806196/

相关文章:

c# - SharePoint 内存泄漏

c# - 使用 C# 驱动程序在 mongodb 中查找计算值最高的文档

.net - 在命令绑定(bind)中使用 WPF 控件自己的属性

android - 进度条显示背景

C代码通过Linux中的蓝牙串行端口配置文件从nonin脉搏血氧计设备读取数据

c# - 是否有任何预制函数可以帮助根据父控件调整控件的大小?

c# - windows phone 7开发app用什么比较好

c# - 在 WPF/C# 中显示时区。发现夏令时偏移

c# - 为什么 RelayCommand RaiseCanExecuteChanged 在单元测试中不起作用?

ios - iOS 上的蓝牙外设卡在 "Connecting"状态