What is the exact difference between xamarin shared project and portable class library?
When to use shared library and when to use portable class library?
Is this possible to write native functionality in shared projects like showing alert,accessing camera and use it for both android and iOS?
Can anyone please explain me.
Shared Projects work well for application developers planning to use lots of platform-specific functionality in their cross-platform apps. While PCL projects continue to be supported in Visual Studio, . NET Standard is recommended for new projects.
What is a Portable Class Library? When you create an Application Project or a Library Project, the resulting DLL is restricted to working on the specific platform it is created for. This prevents you from writing an assembly for a Windows app, and then re-using it on Xamarin. iOS and Xamarin. Android.
NET Standard is platform-agnostic, it can run anywhere, on Windows, Mac, Linux and so on. PCLs can also run cross-platform, but they have a more limited reach. PCLs can only target a limited set of platforms.
Shared Projects let you write common code that is referenced by a number of different application projects. The code is compiled as part of each referencing project and can include compiler directives to help incorporate platform-specific functionality into the shared code base.
#if
compiler directives. When you want to access the camera you need to write the access code inside an #if
block for all destinated platforms. This can mess up your code but it can be easier to find the different implementations. Learn more: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/shared_projects/ System.Net.Http
but you cannot access any platform specific code. If you want to access the camera inside the PCL code then you need to access it by a generalized interface via dependency injection. There are some pretty good frameworks helping you to archieve this goal. One of the most famous is MVVMCross (https://github.com/MvvmCross/MvvmCross/wiki). Learn more about PCL: http://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/sharing_code_options/#Portable_Class_Libraries I personally perefer PCLs because the code is much easier to read without any compiler directives. Using MVVMCross you are able to use plenty of plugins via NuGet. So you don't need to write your own classes for camera access, showing alerts etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With