c# - 使用 Azure IOT 库创建 Xamarin.Forms .Net Standard 应用程序?

标签 c# azure xamarin xamarin.ios xamarin.android

我正在制作一个可与 Azure IoT 中心配合使用的 iOS/Android 应用程序。据我了解,最新的 Microsoft.Azure.Devices 版本仅与 .Net Standard 项目兼容。我一直在尝试按照这些 twho 教程( 12 )将 PCL 项目转换为 .Net Standard 项目,但无济于事,而且我对自己做错的事情感到迷失。

这些是我正在采取的步骤。

  1. 创建名为TestProject的新跨平台应用。 Xamarin.Forms -> 空白应用程序 -> 可移植类库 (PCL)
  2. 右键单击解决方案 -> 添加新项目 -> .Net Standard -> 创建名为 TestProject.Core 的 .Net 标准库
  3. 删除自动生成的类 Class1.cs,并将 App.xamlMainPage.xaml 移动到 TestProject.Core
  4. 删除可移植库TestProject
  5. TestProject.Core重命名为TestProject
  6. 添加对 iOS 和 Android 的 TestProject 引用。
  7. 点击TestProject并选择编辑TestProject.csproj。将 PropertyGroup 更改为以下内容:

    <PropertyGroup> 
     <TargetFramework>netstandard1.4</TargetFramework> 
     <PackageTargetFallback>$(PackageTargetFallback);portable-win+net45+wp8+win81+wpa8
    </PropertyGroup>
    
  8. 右键单击解决方案并选择管理解决方案的 Nuget 包。

  9. 选中包括预发布并在 TestProject、TestProject.Droid 和 TestProject.iOS 上安装 2.3.5.256-pre6 Xamarin.Forms

    <
  10. 清理并重建解决方案。

  11. 右键单击TestProject,然后选择“管理 Nuget 包”。安装Microsft.Azure.Devices

  12. 清理并重建。

  13. 向使用 Microsoft.Azure.Devices 的 TestProject 添加代码。

  14. 重建并出现错误:

    加载程序集时出现项目文件行抑制状态错误异常: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/

相关文章:

c# - 软件包与 netcoreapp2.0 不兼容

c# - MVC System.Runtime.InteropServices.SEHException 在 LocalHost 上运行时

c# - 如何在 MVC 5 中的同一 View 上显示列表和详细信息

c# - 访问 List<List<string>> 的元素

c# - 如何在Azure Function中配置OpenApiRequestBody?

azure - Xamarin 上的 Bing Speech API/语音服务(无 REST,sdk websocket 来处理连续识别)

c# - 自定义控件中的选择器

c# - Xamarin Android 构建失败 "Invalid value for outputAssembly"

c# - 在托管代码中使用 win32

python-3.x - 如何将 Azure-cli 命令的输出保存在变量中