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 Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile】都有那些版本。

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自願者!

 

希望以后大家遇到無法安裝包的時候可以自然的解決了!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM