0
votes

How do your write Xamarin platform specific code in a .net standard library?

I want to use namespaces like Xamarin.Forms.Platform.iOS in a .Net Standard Library..

Use case: I want to develop a .net library for my apps which includes a video player for the various platforms. This video player also has to interact with other code in the .net library.

Or is the answer I need to use a shared project or portable library?

1
You, by definition, cannot include platform specific code in a cross platform library. A cross platform library can only include cross platform code. I'd suggest you look at some common Xamarin plugins on github to see how they are architected - most will have a common shared library as well as platform specific libraries. - Jason
@magicandre1981 thanks I saw that and have read it. - visc

1 Answers

3
votes

You should not include platform specific code or use namespaces like the one you mentioned in your .NET Standard Library, the reason is that .NET is just a runtime environment.

It’s not the the main runtime environment that you would use on iOS or Android. These platforms use Mono - not .NET. Check this or this to see more details for how its structured.

If you need to execute something from your .NET Standard project which is related to platform-specific behavior, use Dependency Injection or Custom Renderers.