Hi
I have been working on a mobile app for some time now using Xamarin forms for ios and Android. I have created a number of custom controls which have custom renderers in each specific platform project. I have a shared library containing all the Xamarin forms stuff and business logic and then my ios and Android projects which have the specific platform stuff - all works great.
I've now started work on another app and I'd like to use the same controls in it but I obviously don't want to have to copy all that code in, I want to create a shared library. I've done some research on this and I've tried almost every combination of New project in Dev Studio (I'm working on a Mac) and I can't seem to fathom how to go about this. Should I be creating a PCL/.Net standard/Xamarin Forms library, how many libraries should I create, etc, etc. I've been reading that PCLs are now defunct and should be replaced by .NET standard but I don't understand Microsoft's parlance when it comes to describing what it does or how it replaces PCLs.
Does anyone have any good documentation on how to do this? I tried creating a Multiplatform library which had a shared project, an IOS and an Android project in it but when I added one of my controls and built it, it built fine and produced a dll but importing that dll into my app showed no signs of my classes available as imports. Building a simple class library does work but that doesn't include API specific code in it.
Bit stuck...
Thanks
Rob
Answers
If you still consumed PCL now I highly recommend we should migrate from PCL to .Net Standard.
There're several documentations demonstrating how to create a .Net Standard library to share code in Xamarin:
https://docs.microsoft.com/en-us/xamarin/cross-platform/app-fundamentals/net-standard?tabs=windows
https://devblogs.microsoft.com/xamarin/net-standard-library-support-for-xamarin/
Thanks for the post but I don't consume any libraries at all at the moment, I'm just trying to decide what to use so I can put my controls into either one single library or a library each for IOS apps and one for Android. Is it even possible to have one library for both IOS and Android classes?
Yes, it could be achieved. Take a look at this Essentials library: https://github.com/xamarin/Essentials/blob/master/Xamarin.Essentials/Xamarin.Essentials.csproj
It could compile different platforms through different ItemGroup in a single library like: