There is a bunch of information online about using .NET Standard for your Xamarin.Forms app, but I'm still confused as to why you would want to use one over the other. The main sources I have read through/watched:
1. Sharing Code Overview (MS docs)
2. .NET Standard 2.0 Support in Xamarin.Forms
3. .NET Standard and Xamarin.Forms for the .NET Developer
My history is I've been a Xamarin developer since the Novell days. Since the introduction of Xamarin.Forms (1.5ish?) I've always used it for creating apps over Xamarin.iOS and Xamarin.Android directly. I've never created a Forms app with PCL, always shared library. One thing I've relied heavily on is the ability to just go:
#if __IOS__
UIApplication.SharedApplication.StatusBarHidden = true;
#elif __ANDROID__
// Other things.
#endif
Being able to do this in the Forms code directly has made things nice and easy. Another example I have used it is in in my own HTTP REST classes, and the ability to use cookie containers in certain ways that would work on both platforms (bugs that may have been resolved now). I now know that in the first example I could create a dependency service called StatusBarActions or something. The second example I know now not to re-invent the wheel and I could just use RestSharp. It's just that one of the listed benefits of using shared code is the ability to use those pre-processor directives.
Likewise two of the main pros of .NET Standard are "Allows you to share code across multiple projects." and "Refactoring operations always update all affected references.". But wouldn't this still be true for a shared Forms app?
Lately I was playing around with converting some smaller in progress apps to be .NET Standard Forms apps. I really enjoy the simplicity of having my main NuGet packages (Xamarin.Essentials, Json.NET, FFImageLoading, sqlite-net-pcl, etc) in the Forms project itself. Its really nice to be able to update all packages at once. The package list also stays nice and short, although I think that's more to do that it doesn't list all package dependencies as new packages. I also liked that it forced me to write cleaner code. Things were good... until I tried Xamarin.Forms on macOS.
Although it is still in preview one of the first things I found that out of the box Xamarin.Essentials was not having a bar of it. It's just one of many packages that may not be supported. It made me think of another project I am working on, Onewheel Community Edition App. It relies heavily on the Plugin.BLE NuGet package that doesn't support macOS or UWP. If I wanted to add either of those platforms I now have to add it via a dependency service or something similar. Alternatively if I used a shared project I could just have a
#if __IOS__ OR __ANDROID__ etc.
I can see both being possible. One makes it easier when a core component is platform specific, but can also make it more of a pain in the case of Xamarin.Essentials when you may just want to use it to display the app version number.
So the real things I want to know are:
- Is it worth it?
- Are there any performance benefits of either?
- Are there binary size or binary security differences that are worth noting.
What are other peoples experience with it shared vs .NET Standard. Are there some other programming paradigms that I am not thinking of to make .NET Standard apps make more sense?