It’s possible convert Xamarin Forms app to Nuget package? - xamarin

I developed Xamarin Forms app with Android and iOS platforms. I would like to know if it’s possible convert this app in a nuget package and run my app in other app.
Of course it would be a nuget package per platform.
I know that importing one project into another can, but I want to protect code. I also don't know if nuget packages can have UI.
Can you help me??
many thanks!!

Related

Which project(s) to install shared libraries in Xamarin App

I want to use a shared class library from my backend API in my Xamarin Forms 5 app. This library mostly contains some util functions and I have it as a NuGet package.
Do I need to install this package on all three projects or just the main project where I have my code and where I'll be using it?
I read some articles and watched some videos and got some conflicting answers. In some cases, packages are installed onto all three projects but other times only onto the main one. I'm sure there's some logic to this. I'd appreciate someone telling me how to determine where to install NuGet packages like mine?
if it's just a .NET library, install it in your .NET project where all the Forms code is
nugets that are installed in multiple projects typically contain multiple libraries - iOS, Android and .NET, and nuget installs the appropriate library in each one

Install Nuget on Xamarin.Forms for every proyect or not

When you install a nuget in Xamarin.Forms is it necessary to do it on every project (project, project.Android and project.IOS)?
Which pros and cons has do it or how I know where I have to intall each of them?
There is no absolute answer, it will depend on the Nuget Package. So you will have to read the information about it before deciding to install it in your project.
What defines this?
Take for example Xamarin.Essentials, it is installed in all the projects because you can call the functions in share code, but the actual implementation is in the platform specific. In this case you even have to call Init in every platform
From Xamarin.Essentials doc
In the Solution Explorer panel, right click on the solution name and
select Manage NuGet Packages. Search for Xamarin.Essentials and
install the package into ALL projects including Android, iOS, UWP, and
.NET Standard libraries.
If you apply platform specific code, you might need some extra Nugets for that code, meaning that you would only add it to your Android or iOS or UWP code
If you have any doubt about where to install the package, you can always ask :) Also if you install an Android package in an iOS project, you surely will get a compiling error.

Could not install package 'FormsPinView 1.1.0'. in Xamarin forms

I am trying to install Device LockScreen FormsPinView package in Xamarin forms using PCL but its not install in my PCL project.
and facing the below error while doing so.
Could not install package 'FormsPinView 1.1.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Any help is appreciated.
Convert your project to .NET Standard 2.0 it will solve the issue described above and will help you in many other ways. There are 4 simple steps that you have to make and they are described in this gist, however if you are using Visual Studio for Mac you could automate the conversation process by using extension called Mutation.
You can find more details on the official Xamarin blog.
I also wrote a short article on this topic.
Good luck.

Using platform specific httclienthandler?

In xamarin should I always configure the app to use the platform specific httpclienthandler or is it ok to use the default httpclienthandler. I have read that you get better performance but I was just wondering if it is so much better that this should be a standard practice for all my xamarin apps.
It is ok to use httpclienthandler in the portable class library(pcl). Feel free to use HttpClient to run in a PCL library that supports iOS, Android, and WP8.
Here how i did it. Restart from a clean project.
Create a PCL with iOS, Android, .NET 4.5 and WP8. Add the microsoft Http nuget. It will install 2 other packages into the PCL.
Create the Android and iOS projects. Reference your PCL in both projects. For me that's all. It just works.
You may add the reference "System.Net.Http" in both platform projects. The reference is under Assemblies/Framework.
NEVER add Microsoft.Http nuget in any native project, nor the BCL nuget. It will create mess and you'll have to clean lots of things before it can work again.
It is extremely important that your NuGet manager is up to date, go to Tools-> Extensions and updates -> Updates

C# Nuget References

I'm a bit confused about the dlls that are installed when using Nuget to install libraries to my Xamarin Projects. I mainly manage the nugets for the whole solution. So when i install a nuget i choose all platform projects as targets, meaning the PCL, the Android and the iOS Project. In most cases there are different dlls, like #.XForms, #.XForms.Android and #.Android, for example in the Community Toolkit (FormsCommunityToolkit), which is also available from Nuget.
In my understanding the .Android dlls need to be used in the android platform project, and the XForms dll without android should be used in the PCL. A good example is the Converters.dll. That's code only used in the pcl, but the dll is also automatically referenced in the platform projects. So my question is, why is this the case?
I see this behavior not only for this toolkit but also for other apis, like Syncfusion.
PCL dlls will contain codes that accessing common API for the targeted PCL profiles. For the UI project (Android and iOS) need to be using different dlls most of the time because it need to access to platform specific APIs. For example, API to check network connection is different in iOS and Android.
But you should not be worry about which dlls to use. NuGet package manager already handle which dlls to be use in the solutions. So, you will just need to include the packages and let the package manager to handle the rest of it.

Resources