【问题标题】:Creating Xamarin.Forms .Net Standard app with Azure IOT Library?使用 Azure IOT 库创建 Xamarin.Forms .Net 标准应用程序?
【发布时间】:2018-02-10 19:37:59
【问题描述】:

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

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

  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. 添加 TestProject 对 iOS 和 Android 的引用。
  7. 点击TestProject并选择Edit TestProject.csproj。将 PropertyGroup 更改为以下:

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

  9. 勾选Include Prerelease并在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. 

【问题讨论】:

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


    【解决方案1】:

    我正在制作一个适用于 Azure IoT Hub 的 iOS/Android 应用。据我了解,最新的 Microsoft.Azure.Devices 版本仅与 .Net Standard 项目兼容。

    据我了解,您可以利用支持 Android、iOS、Windows 10 (UWP) 和 Windows Phone (WinRT) 的 Azure IoT Hub 客户端 SDK 便携式库 Microsoft.Azure.Devices.Client.PCL。另外,这里有一个使用Microsoft.Azure.Devices.Client.PCL的示例,您可以关注here

    【讨论】:

    • PCL不支持MQTT协议,很快就会被net standard support替换:Reference目前推荐的解决方案是创建NetStandard 1.3类库,添加设备客户端,引用在 xamarin android 项目中。 ReferenceImplementation
    猜你喜欢
    • 1970-01-01
    • 2018-06-21
    • 2017-09-07
    • 2018-03-23
    • 2020-11-17
    • 1970-01-01
    • 2019-06-18
    • 2018-01-11
    • 1970-01-01
    相关资源
    最近更新 更多