我正在制作一个可与 Azure IoT 中心配合使用的 iOS/Android 应用程序。据我了解,最新的 Microsoft.Azure.Devices 版本仅与 .Net Standard 项目兼容。我一直在尝试按照这些 twho 教程( 1 、 2 )将 PCL 项目转换为 .Net Standard 项目,但无济于事,而且我对自己做错的事情感到迷失。
这些是我正在采取的步骤。
- 创建名为TestProject的新跨平台应用。 Xamarin.Forms -> 空白应用程序 -> 可移植类库 (PCL)
- 右键单击解决方案 -> 添加新项目 -> .Net Standard -> 创建名为 TestProject.Core 的 .Net 标准库
- 删除自动生成的类 Class1.cs,并将 App.xaml 和 MainPage.xaml 移动到 TestProject.Core。
- 删除可移植库TestProject。
- 将TestProject.Core重命名为TestProject。
- 添加对 iOS 和 Android 的 TestProject 引用。
点击TestProject并选择编辑TestProject.csproj。将 PropertyGroup 更改为以下内容:
<PropertyGroup> <TargetFramework>netstandard1.4</TargetFramework> <PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8 </PropertyGroup>
右键单击解决方案并选择管理解决方案的 Nuget 包。
选中包括预发布并在 TestProject、TestProject.Droid 和 TestProject.iOS 上安装 2.3.5.256-pre6 Xamarin.Forms。
<清理并重建解决方案。
右键单击TestProject,然后选择“管理 Nuget 包”。安装Microsft.Azure.Devices
清理并重建。
向使用 Microsoft.Azure.Devices 的 TestProject 添加代码。
重建并出现错误:
加载程序集时出现项目文件行抑制状态错误异常:System.IO.FileNotFoundException: 无法加载程序集“Microsoft.Azure.Devices,版本=1.0.0.0,文化=中性,PublicKeyToken=31bf3856ad364e35”。 也许它不存在于 Mono for Android 配置文件中?文件名:“Microsoft.Azure.Devices.dll”
据我所知,我缺少 Microsoft.Azure.Devices Nuget 包 TestProject.Droid,但是,当我尝试安装它时,出现以下错误:
Could not install package 'System.Threading.Overlapped 4.3.0'.
You are trying to install this package into a project that targets
'MonoAndroid,Version=v7.1', but the package does not contain any assembly references or
content files that are compatible with that framework.
当我尝试在 iOS 上安装 *Microsoft.Azure.Devices** 时:
Could not install package 'System.Threading.Overlapped 4.3.0'. You are trying to install
this package into a project that targets 'Xamarin.iOS,Version=v1.0', but the package does not
contain any assembly references or content files that are compatible with that framework.
最佳答案
I'm making an iOS/Android app that will work with Azure IoT Hub. The latest Microsoft.Azure.Devices version from what I understand is only compatible with .Net Standard projects.
根据我的理解,您可以利用 Azure IoT 中心客户端 SDK 可移植库 Microsoft.Azure.Devices.Client.PCL它支持 Android、iOS、Windows 10 (UWP) 和 Windows Phone (WinRT)。另外,这里是一个使用 Microsoft.Azure.Devices.Client.PCL
的示例,您可以按照 here .
关于c# - 使用 Azure IOT 库创建 Xamarin.Forms .Net Standard 应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46005308/