簡體   English   中英

我是否可以僅使用Xamarin PCL來定位iOS和Android並具有更多.NET功能?

[英]Can I target iOS and Android only with a Xamarin PCL and have more .NET features?

我需要在Xamarin中創建一個僅針對iOS和Android的庫。 我不需要支持任何其他平台,但我需要盡可能多的.NET功能。

我看到在Change Targets對話框中無法取消選中Silverlight復選框:

在此輸入圖像描述

我是否可以創建一個Xamarin便攜式類庫,僅針對iOS和Android而不支持Silverlight並支持更多.NET功能?

編輯:這是我需要支持的一些類:X509CertificateCollection,SerializationInfo,NameValueCollection。 我還需要System.Web.Services名稱空間支持。 看起來我可以直接在iOS和Android項目中使用所有這些。 我可以創建具有所有這些功能的PCL嗎?

Profile24,其中包括Silverlight是你將獲得的最窄,包括Xamarin.iOSXamarin.Android

僅供參考:我完全同意Matt關於使用Profile111的建議,如果您要進入PCL庫方向。 有時對於我們的項目,只需使用“共享項目”並在需要時在共享代碼中使用#if /#else / #end,就會“更快”($ / time)。 PCL庫非常適合共享,但如果你不需要留下框架片的心痛,那么共享的項目方向今天可以解決今天的問題...... ;-)

從Xamarin 4.1版本開始,添加了兩個新的配置文件:

Profile 44  (.NET Framework 4.5.1, Windows 8.1) (netstandard 1.2)
Profile 151 (.NET Framework 4.5.1, Windows 8.1, Windows Phone 8.1) (netstandard 1.2)

舊的:

Profile 5   (.NET Framework 4,     Windows 8)
Profile 6   (.NET Framework 4.0.3, Windows 8)
Profile 7   (.NET Framework 4.5,   Windows 8)
Profile 14  (.NET Framework 4,     Silverlight 5)
Profile 19  (.NET Framework 4.0.3, Silverlight 5)
Profile 24  (.NET Framework 4.5,   Silverlight 5)
Profile 37  (.NET Framework 4,     Silverlight 5, Windows 8)
Profile 42  (.NET Framework 4.0.3, Silverlight 5, Windows 8)
Profile 47  (.NET Framework 4.5,   Silverlight 5, Windows 8)
Profile 49  (.NET Framework 4.5,   Windows Phone Silverlight 8)
Profile 78  (.NET Framework 4.5,   Windows 8, Windows Phone Silverlight 8)
Profile 92  (.NET Framework 4,     Windows 8, Windows Phone 8.1)
Profile 102 (.NET Framework 4.0.3, Windows 8, Windows Phone 8.1)
Profile 111 (.NET Framework 4.5,   Windows 8, Windows Phone 8.1)
Profile 136 (.NET Framework 4,     Silverlight 5, Windows 8, Windows Phone Silverlight 8)
Profile 147 (.NET Framework 4.0.3, Silverlight 5, Windows 8, Windows Phone Silverlight 8)
Profile 158 (.NET Framework 4.5,   Silverlight 5, Windows 8, Windows Phone Silverlight 8)
Profile 225 (.NET Framework 4,     Silverlight 5, Windows 8, Windows Phone 8.1)
Profile 255 (.NET Framework 4.5,   Silverlight 5, Windows 8, Windows Phone 8.1)
Profile 259 (.NET Framework 4.5,   Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)
Profile 328 (.NET Framework 4,     Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)
Profile 336 (.NET Framework 4.0.3, Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)
Profile 344 (.NET Framework 4.5,   Silverlight 5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)

http://danrigby.com/2014/05/14/supported-pcl-profiles-xamarin-for-visual-studio-2/

如果您嘗試定位PCL,您將受到限制,另一種選擇是使用Bait-and-Switch NuGet,其設置如下:

  • 共享項目 - 包含所有共享代碼
  • Android庫項目 - 引用共享項目,因此它獲取所有代碼
  • iOS庫項目 - 引用共享項目,因此它獲取所有代碼
  • PCL項目 - 空項目,僅包含方法的空存根

然后創建一個NuGet,其中Android有效負載是Android Library項目,iOS有效負載是iOS Library項目。

然后,PCL項目只顯示與PCL兼容的API,但實現恰好使用了您需要的所有內容。

對於誘餌和轉換方法,請參閱: http//log.paulbetts.org/the-bait-and-switch-pcl-trick/

PCL配置文件(幾乎)相同,包括或不包括Silverlight,您只能訪問PCL程序集。

但是,Xamarin Forms已經允許您應對這一點,在每個平台上都有.Droid和.iOS項目,在這些項目中,您可以使用完整的.net框架。

要從這些項目中訪問代碼,您需要具有Dependency Services ,如果您想為Android和iOS使用相同的代碼,則您可以共享項目

基本上,將所有共享編碼放在共享項目中,實現接口,將其注冊為依賴服務,在Forms代碼中檢索它,這樣您就可以獲得對完整框架的支持。

正如文本告訴你的那樣,它將自動添加silverlight,因為不會削減功能。 因此將不再有可用的功能。

另一方面,我建議使用Profile111 (參見SushiHangover答案中的列表)。 一方面,這允許您稍后將Windows 10添加為目標平台,並且大多數PCL似乎都支持此配置文件,因為Silverlight將會死(Silverlight 5是最后一個,Windows Phone是UWP)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM