gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 06:00:13 25 4
gpt4 key购买 nike

我在使用 .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 StateError CS0012 The type 'BluetoothLEDevice' is defined in an assemblythat 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com