Xamarin - NetStandard and Android - xamarin

I have a project (A) which is a NetStandard 2.0 project. I also have an Xamarin Android Library project (B) which uses project A. I want to make project B a nugget (Azure DevOps) so I can install it in multiple projects.
When I compile on my local computer, everything is fine. However, the Azure pipeline always come out with this error "Package XYZ is not compatible with monoandroid90 (MonoAndroid,Version=v9.0). Package XYZ 2022.5.13.1 supports: netstandard2.0 (.NETStandard,Version=v2.0)". Package XYZ is a .netStandard2.0 project because it is also (mainly) used within my base Xamarin Project.
XYZ contains an Interface which I implement in my Android project (B) (my base Xamarin Project uses it via DependencyServices).
The only way I can use it in other projects right now is to add the compiled .dll manually.
Anything I'm not seeing here ? Made numerous searches but I'm still clueless.

Related

Why can't I add my NuGet package to my app in Visual Studio?

I'm using Visual Studio for Mac on macOS Big Sur (11.2.3) to try to create a cross-platform NuGet package encapsulating common logic to be added to some Xamarin.Forms mobile apps.
I begin by creating a new solution and choosing Multiplatform -> Library -> Multiplatform Library. Under Target Platforms: I check the boxes for both iOS and Android. Under Implementation: I check Platform specific.
I add the platform-specific code to the iOS and Android projects, and shared code to the Shared directory, with no problem. The NuGet package builds without error.
But when I try to add the package to one of the Xamarin.Forms apps, VS raises the error Could not add packages and writes this to the package console:
Package <my package name> 1.0.0 is not compatible with netstandard2.0 (.NETStandard,Version=v2.0). Package <my package name> 1.0.0 supports:
- monoandroid11.0 (MonoAndroid,Version=v11.0)
- xamarinios10 (Xamarin.iOS,Version=v1.0)
I did try adding <TargetFramework>netstandard2.0</TargetFramework> to the .csproj files in the library projects, but that caused an explosion of errors that made it clear that was the wrong approach.
This is outside my existing expertise, and I'm at the end of my limited understanding. How do I build/modify this package so that it can be added to a mobile app solution?

Does a .Net standard Xamarin.Forms application have the Dependencies, NuGet and SDK folder in the Android and iOS projects?

I am a bit confused about implementing the .Net standard application which has a iOS and Android project.
Can someone tell me does a .Net standard Xamarin.Forms application have the Dependencies, NuGet and SDK folder in the Android and iOS projects?
Can someone tell me does a .Net standard Xamarin.Forms application
have the Dependencies, NuGet and SDK folder in the Android and iOS
projects?
Platform targeting projects cannot be a .NET Standard projects, therefore there are minor differences in the structure.
Dependencies -> References - Can be a reference to another project or assembly. Defined in the csproj and depends on your setup should be in the solution.
NuGet -> Packages - defined in the csproj and depends on the setup may live under packages directory within the solution or in a NuGet cache.
SDK directory is missing. It is set under project options in the Target framework.

Using FluentMigrator in a Xamarin Portable Class Library

I have created a Xamarin Forms project within VS 2017 Community Edition. I would like to use FluentMigrator to create a a database for use within the application.
When I attempt to use NuGet PM to install FluentMigrator into the project, I get the following error:
Could not install package 'FluentMigrator 1.6.2'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile259', 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.
I am guessing it's the fact that my project is using.NETPortable.
Is it possible to use FluentMigrator within a Xamarin PCL? If so, what needs to be changed in my project configuration?
The FluentMigrator does not have any assemblies that are compatible with PCL projects. It contains two lib directories: 35 and 40. These seem to have .NET assemblies for .NET 3.5 and .NET 4.0. So you cannot install this into a PCL project.
I would instead see if you can just create a .NET project, say targeting .NET 4.5, and install the FluentMigrator NuGet package into that project and define your migrations there.

Can not compile after migrating unified api in xamarin forms

We have migrated the xamarin forms project to unified api.
But we have the strange compile error like this:
Could not AOT the assembly '.../iOS/obj/iPhone/Debug/mtouch-cache/Build/Xamarin.Forms.Labs.dll
So I changed the settings in iOS project's options.
In ios Build Tab of Project options(iOS) I changed the "don't link" to "Link all assemblies".
But the app is crashed when it is started.
xamarin version is 5.7.1(build 17).
xamarin forms's version is 1.3.5.6337.
xamarin forms labs's version is 1.0.1.5.
Please help me if you have the experience with this error.
Replace Xamarin.Forms.Labs with XLabs.Forms.
There has been a major refactoring on how the XLabs project is structured so your existing project based on the 1.x.x will break. The reason for the refactoring was simple; separate functionality that does not depend on Xamarin.Forms into different assemblies. This allows the use of functionality like IoC, Serialization and even platform specific services without referencing XF.
To upgrade:
Uninstall any existing Xamarin.Forms.Labs packages from your
project.
Install XLabs.Forms package to your projects (PCL, iOS, Droid & WP). This will update Xamarin.Forms to the latest stable release (1.4.x)
Refactor code to reference the correct namespaces.

Can I add .NET 3.5+ NuGet packages to a Mono for Android project?

Mono for Android has access to most of .NET 4.0 from the Mono framework. Unfortunately, when I try to add NuGet packages in Visual Studio that specifically target .NET 3.5 or beyond, with a /lib/net*/ folder structure, it tosses up an error.
You are trying to install this package into a project that targets
'MonoAndroid,Version=v2.1', but the package does not contain any
assembly references that are compatible with that framework.
If a NuGet package doesn't have the .NET version breakdown, or one where you removed that subdirectory structure and published it to a NuGet source, it works fine. For example, NUnit just has a /lib/ folder with no further breakdown by .NET framework version and installed fine.
It appears NuGet could be checking compatibility by using the <TargetFrameworkVersion> project file XML element. If so, that is the problem as Mono for Android usurps that element to mean a "target Android framework version". For example, to target Android v2.2, it looks like this:
<TargetFrameworkVersion>v2.1</TargetFrameworkVersion>
In the project properties dialog, where the "[.NET] Target framework" drop-down would be is a drop-down for "Minimum Android to target" that affects this XML element.
If this is the problem NuGet is encountering, I won't be able to use unmodified NuGet for version-specific packages until targeting an Android app for a minimum of Ice Cream Sandwich (v4.0).
Side note
You can reference the DLLs from these packages via project reference. It definitely throws a warning at you, but you can ignore it fairly safely (assuming the assembly doesn't wander too far from the code implemented in Mono).
'Some.dll', or one of its dependencies, requires a later version of
the .NET Framework than the one specified in the project...
No, assemblies must be compiled against the 2.0.5 profile in order to be used by Mono for Android. You can achieve this by using the Mono for Android Class Library template or by using assemblies compiled for Silverlight.
The Android version (2.2, 3.0, 4.0) is not related to the version of the .NET BCL an assembly is compiled against.

Resources