Adding .NET liblaries to Xamarin project - xamarin

How to add a library for Windows to cross-platform Xamarin project in Visual Studio?
Example, we have some 3rd party service with API and DLL binaries for this API. The service provides DLL for WP, Android, iOS and .NET, but not for Xamarin. Can I use it for Xamarin.Android и Xamarin.iOS?
I have tried to connect WP or .NET DLL to the projects, but it doesn't work.

I have done something similar.
I created a libs folder under my Droid project and placed the Android-specific libraries in there.
I then added the DLL's to my project (using the Add Files option) and, this is important, changed the Build action to EmbeddedResource.
From there, I could access the packages as expected and work with the library.

Related

No portable class library folder found in Xamarin Forms

I am a newbie working with Xamarin Forms in Visual studio 2019.
When I create a blank page for Mobile App(Xamarin.Forms) , I do not see a Xamarin.forms portable template app in my project solution.
There is no PCL anymore. PCL is outdated. Just use the Mobile App (Xamarin.Forms) template. It will create all you need.
The core project (that contains your shared code) will be a .net standard project.
.net standard is way better than PCL, because you don't have a artificially limited set of APIs.
this creates the following 3 projects
Your shared code should go into the App8 project

Cannot find "cross-platform using PCL" while creating a xamarin app

I want to create a xamarin cross platform using PCL. I do not find this option while creating a project. Am I missing any installations?
Is "Xamarin.UITest Cross Platform Test Project" similar to that? But that does not open Android and IOS directories in it
The PCL option is deprecated .
From the official documentation:
Portable Class Libraries (PCLs) are considered deprecated in the
latest versions of Visual Studio. While you can still open, edit, and
compile PCLs, for new projects it is recommended to use .NET Standard
libraries to access a larger API surface area.
If you wan't to create a Xamarin.Forms solution, you must select the Mobile App (Xamarin.Forms) template. Nowadays, everything moved to .netstandard 2.0

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.

Using a windows.dll in a Xamarin project to deploy on an iPad

I have a C# library that I want to use in my Xamarin project to deploy to an iPad.
Lets suppose the C# library is stored as MyUtilities.dll.
For a regular Windows app, I'd add MyUtilities.dll to my project Resources and then have a
using MyUtilities;
statement in the class where I wanted to use classes from that library.
How do I accomplish this same thing using Xamarin in an iPad app?
You will need to rebuild your library from the source using the Xamarin.iOS compiler. After that you would reference the same way you do in a Windows app - by either including a Reference to the dll in your project, or by including the Library project in your solution and referencing the project.

Common library for Windows Phone and Android App projects

I am developing a windows phone app and an android app. Both the apps are under one visual studio 2010 solution.
I wanted to include a third project under the same solution which contains common functionality that both windows and android app uses. So, for this when I use plain 'Class Library' and when I try to reference that in windows phone app project, it says "Unable to add the selected project reference. The project reference must be another Silverlight for Windows Phone project that is same or lower version".
Which type of project do you suggest, so that I can use it windows phone and android projects?
You will have to use two different csproj files - because the build targets and other pieces will be different for the two platforms. Use this recursive include in each csproj to add the sources from a common location.
You can also try to use the Portable class library extension but I'm not sure if it will help.

Resources