• Xamarin+Prism开发详解一:PCL跨平台类库与Profile的关系


    在【Xamarin+Prism小试牛刀:定制跨平台Outlook邮箱应用】中提到过以下错误,不知道大伙还记得不:

    无法安装程序包“Microsoft.Identity.Client 1.0.304142221-alpha”。你正在尝试将此程序包安装到目标为“.NETPortable,Version=v4.5,Profile=Profile111”的项目中,但该程序包不包含任何与该框架兼容的程序集引用或内容文件。有关详细信息,请联系程序包作者。

    不只是Microsoft.Identity.Client 有以上错误,有名的条形码二维码类库ZXing.Net.Mobile等也只支持Profile7。那Profile是什么?Profile111又是什么了?今天一一为你揭秘。

    PCL (Portable Class Library)

    PCL是跨平台代码共享的一种设计方式,简称可移植类库。Xamarin.Adroid,Xamarin.iOS.UWP都可以直接参照调用。主要是将平台无关的业务代码创建为PCL类库,不过随着MVVM框架的流行,Xamarin.Forms已经将View,ViewModel,Model都移植到了PCL类库,部分平台依赖比较强就分平台实现。

    Profile

    PCL类库对应的平台集合不一样,对应的Profile版本也不一样。如果自定义的PCL类库与Nuge上PCL包的Profile不一致,将导致开题的错误无法安装。

    image

    比如上图PCL类库的目标集合对应的Profile如下(.csproj工程文件):

    image

    全部的Profile版本如下:

    f:id:ytabuchi:20141210132212p:plain

    .NET 4.5目前对应的Profile为7,49,78,111,259. 可以查看本地目录【C:Program Files (x86)Reference AssembliesMicrosoftFramework.NETPortablev4.5Profile】都有那些版本。

    image

    具体的对应关系如下表:(Visual Studio 2015 Update3/Windows10环境)

    Profile VS目标设置 对应平台
    Profile7 image
    • .NET 4.5
    • Windows 8 (含UWP)
    • Windows Store apps (Windows 8)
    • Xamarin.Android
    • Xamarin.iOS Classic
    • Xamarin.iOS Unified
    • Asp.NET core1.0
    Profile49 image
    • NET 4.5
    • Windows Phone 8 or later
    • Windows Phone Sliverlight 8
    • Xamarin.Android
    • Xamarin.iOS Classic
    • Xamarin.iOS Unified
    • Asp.NET core1.0
    Profile78 image
    • .NET 4.5
    • Windows Phone 8 or later
    • Windows 8(含UWP)
    • Windows Phone Sliverlight 8
    • Windows Store apps (Windows 8)
    • Xamarin.Android
    • Xamarin.iOS Classic
    • Xamarin.iOS Unified
    • Asp.NET core1.0
    Profile111 image
    • NET 4.5
    • Windows Phone 8.1 or later
    • Windows 8(含UWP)
    • Xamarin.Android
    • Xamarin.iOS Classic
    • Xamarin.iOS Unified
    • Asp.NET core1.0
    Profile259 image
    • .NET 4.5
    • Windows Phone 8.1 or later
    • Windows 8(含UWP)
    • Windows Phone Sliverlight 8
    • Windows Store apps (Windows 8)
    • Xamarin.Android
    • Xamarin.iOS Classic
    • Xamarin.iOS Unified
    • Asp.NET core1.0

    没有System.Net.Http

    Xamarin.Forms for Windows 开发的时候最好是使用Profile 7, 111, 259 。

    Xamarin.Forms for UWP 开发的时候最好是使用Profile 111。

    【备注】

    Profile259没有System.Net.Http库,得安装微软的System.Net.Http包。目前流行的Http操作类库RestSharep也在招募PCL与UWP自愿者!

    希望以后大家遇到无法安装包的时候可以自然的解决了!

  • 相关阅读:
    天心阁漫步
    大美湘江
    easyui tree基本操作
    盗墓笔记
    半年了
    文件上传控件值发生变化后自动提交表单
    宁静的夏夜
    今天您给别人让座,将来别人给您让座
    优先队列priority_queue 用法详解
    POJ2387
  • 原文地址:https://www.cnblogs.com/lixiaobin/p/PCLProfile.html
Copyright © 2020-2023  润新知