Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I need to create a library in Xamarin that targets iOS and Android only. I do not need to support any other platforms, but I need as much .NET features as possible.

I see that in Change Targets dialog there is no way to uncheck Silverlight check-box:

enter image description here

Can I create a Xamarin portable class library that targets iOS and Android only without Silverlight support and have more .NET features supported?

EDIT: Here are some classes that I need to support: X509CertificateCollection, SerializationInfo, NameValueCollection. I also need System.Web.Services namespace support. It looks like I can use all these in iOS and Android projects directly. Can I create PCL with all these features?

like image 249
IT Hit WebDAV Avatar asked May 03 '16 17:05

IT Hit WebDAV


2 Answers

While you will be limited if you try to target PCL, another option is to use a Bait-and-Switch NuGet, which would be setup as follows:

  • Shared Project - Contains all your shared code
  • Android Library Project - References Shared Project, so it gets all the code
  • iOS Library Project - References Shared Project, so it gets all the code
  • PCL Project - Empty project, which only contains empty stubs for the methods

Then you create a NuGet, where the Android payload is the Android Library project, and the iOS payload is the iOS Library project.

The PCL project then only surfaces the API that is PCL compatible, but the implementation happens to use everything you need.

For bait-and-switch approach see: http://log.paulbetts.org/the-bait-and-switch-pcl-trick/

like image 160
miguel.de.icaza Avatar answered Oct 07 '22 15:10

miguel.de.icaza


Profile24, which includes Silverlight is the narrowest you are going to get while include Xamarin.iOS and Xamarin.Android

FYI: I totally agree with Matt's suggestion of using Profile111 if you are going the PCL library direction. Sometimes for our projects, it is "faster" ($/time) to just go with "Shared Projects" and use #if/#else/#end in the shared code when needed. PCL libraries are great for sharing, but if you do not need the heartache of leaving framework pieces behind, the shared project direction can solve today's problem today... ;-)

As of the Xamarin 4.1 release two new profiles were added:

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)

Old ones:

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/

like image 22
SushiHangover Avatar answered Oct 07 '22 13:10

SushiHangover