0

I need to create a reusable Xamarin Forms control that will be used in two separate projects. It does require custom renderers for IOS and Android. The problem is I cannot figure our what kind of project to use to create a reusable custom control library for Xamarin forms.

Every site seems to talk about creating customer controls that can be reusing in the same project. But I need it in a separate project for reuse.

Can someone please point me in the right direction.

Cfun
  • 8,442
  • 4
  • 30
  • 62
  • use a .NET Standard library for the shared Forms library. VS Mac has a "Multiplatform LIbrary" template, I don't know if VS2019 has the same thing. – Jason Apr 30 '21 at 16:31
  • .Net Standard lets me share code but I need to create controls with custom renderers. Also windows does not appear to have the multiplatform library template – Christopher James Woods Apr 30 '21 at 16:33
  • you will have libraries for each platform and a shared library with any common code – Jason Apr 30 '21 at 16:37

1 Answers1

0

Depending what are your needs regarding multi-targeting, using a solution with a shared project of type MSBuild.Sdk.Extras could be very helpful. You can then packed your shared project into a package that you can reference from your apps project and use locally.

Examples that might guide you and shows you the path are known nuget packages that are being used by app developers cross-platforms, just an example Xamarin.Forms.PancakeView.

Related to MSBuild.Sdk.Extras: How to use different base class in custom control depending on platform target?

Cfun
  • 8,442
  • 4
  • 30
  • 62
  • What I am looking for is a template that generates the same three projects as a new xamarn.forms app but can be used for custom controls. With one main project and one project for ios and one for android. Is that not possable? – Christopher James Woods Apr 30 '21 at 16:48
  • I didn't quite understand, do you want a template project that brings code that you used to use ? using a custom package will ensure the reusability that you are looking for which is a cleaner way to achieve that. you just need to add a reference to your package that contains the reusable code. – Cfun Apr 30 '21 at 16:51
  • No, I want to create a custom control library for Xamarin.Forms. When you create a new Xamarin.Forms app it creates three projects. A main project and one for IOS and one for Android. I want to do the same thing but as a control library instead of an app. At the moment there does not seem to be any way to create a custom control library for xamarn.forms. – Christopher James Woods Apr 30 '21 at 16:54