'Could not add Microsoft.ProjectOxford.Face' Why can't I add this nuget to my Xamarin.Forms.iOS project? - xamarin

I am trying to work with facerecognition in xamarin forms by following these guides:
https://blog.xamarin.com/building-smart-apps-with-microsoft-cognitive-services/
https://blog.xamarin.com/adding-facial-recognition-to-your-mobile-apps/
When I add the needed packages: Microsoft.ProjectOxford.Face and Microsoft.ProjectOxford.Common to my shared project it works but once I add them to my iOS project the Microsoft.ProjectOxford.Face does not get added with the following error message:
Could not install package 'Microsoft.ProjectOxford.Face 1.1.0'. You are trying to install this package into a project that targets 'Xamarin.iOS,Version=v1.0', 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 have tried to install every version from it, all the way from 1.1.0 to 1.2.5.1.
I have the Newtonsoft.Json package installed as well as the Microsoft.Net.Http as well that is required.
Any idea how I can solve this?

You do not need to add this package to your platform projects. Since this i just a wrapper to access the Cognitive Services APIs it will work directly from the shared code.
The only time you need to install a NuGet on both your shared as well as your platform projects is when it leverages platform specific features. Have a look at the Dependency Service which is included in Xamarin.Forms.
That is basically what those NuGets do, they provide you with an interface to use in your shared code, but under the hood functionality is injected from the platform that you are running on.
In this case there is no need to access platform specific features, so you can just install it on your PCL and it should work.

Related

What is the relationship between the NetStandard.Library NuGet package and the Target Framework in project properties?

I have a .NET Standard class library project. I want the library to be available to the broadest array of consuming applications, so following Microsoft's advice here, I am targeting .NET Standard 1.3 in my project properties.
However, there is also a NuGet package called NetStandard.Library. And somewhere along the line, my project got a reference to this as well. What's more, it's a different version (1.6). I'm confused. Is this okay?
What is the relationship between these?
And somewhere along the line, my project got a reference to this as
well. What's more, it's a different version (1.6). I'm confused. Is
this okay? What is the relationship between these?
I think you should not worry too much about that.
1.6.1 is just the version of NetStandard.Library nuget package and it has nothing to do with the version of the target platform, and they don't interfere with each other.
The NetStandard.Library nuget package just service the related net standard project and provide any libs and apis to develop,build, debug the current project.
Besdies, NetStandard.Library 1.6.1 service net standard 1.x project while NetStandard.Library 2.0.3 services net standard 2.x projects.
So when you finishing developing it and pack your net standard 1.3 lib project as nuget package and then use it in target platform, actually, NetStandard.Library nuget package already finish its job and it is irrelevant in this step.
When you use such net standard project into other target platform projects, you only need to consider that whether the net standard version and the target platform version are within the scope of support as your linked document describes.
--------------Update 1-------------
Actually, sure.1.6.1 version is just only the nuget package version. NetStandard.Library 1.6.1 nuget package defines one or more standard.net version libraries.
And as far as I know, 1.6.1 version supports net standard 1.0~1.6 class library projects and the nuget package services for those net standard version.
And then it will direct the current project to the corresponding target platform projects.
Hope it could help you.

NuGet Package Manager does not install package with highest depencency version?

This must be a bug of the NuGet Package Manager I'm using (version 4.6.0). I used the option DependencyVersion highest but it always picks the lowest version for dependencies.
Like this (I'm trying to install Serilog.AspNetCore with dependencies of 2.2.0 - the latest but 2.0.0 is always picked).
install-package Serilog.AspNetCore -DependencyVersion highest
One dependency it picks is Microsoft.AspNetCore.Http.Abstractions 2.0.0 but I expected it to pick Microsoft.AspNetCore.Http.Abstractions 2.2.0.
It's important because in my project the version 2.2.0 is required, Serilog should adapt that requirement by installing with that correct version of dependencies. But here I could not do anything to help it understand what I want.
Also the Install and Update options are not shown in the UI of NuGet Package Manager (the DependencyVersion could be selected there as well when using UI to install packages). So this appears to be some bug at least in the specific version of Nuget package manager I'm using.
What could I do to solve this issue? Can I try fixing the installed nuget manager (there is not any update in the Updates window). Thanks!
UPDATE
I've just tried a traditional .NET project, it works. But the problem raised when my projects target .NET Core (ASP.NET Core)? Looks like it does not support that feature for .NET Core projects?
The DependencyVersion switch is something used to control the behavior when NuGet looks for patch versions. It seems to be introduced after NuGet 2.8, but one point we should know is this option only supports packages.config format.
There are two package management formats:Projects.config and PackageReference.
1.For traditional .net project:It can use Packages.config or PackageReference to manage its nuget packages.But by default it uses packages.config.
2.For .net core projects(which uses new SDK-format project file):It uses new PackageReference format as its Package Management format.
More details about it see: Project Type Support
And someone had post this feature request in github, see the issue here.Hope it helps.
Update:
I expected it to pick Microsoft.AspNetCore.Http.Abstractions 2.2.0
Trying deleting the bin and obj folder first,
Then go Tools menu=>Nuget Package Manager=>Package Manager Settings=>Clear All Nuget Caches.(Sometimes it will delete the packages folder in C:\Users\lancel\.nuget\packages, we need to manually create a new packages folder)
Then install the Microsoft.AspNetCore.Http.Abstractions 2.2.0 package separately before installing the Serilog.AspNetCore package. Builds the application and you can check the output .dll by setting the CopyLocalLockFileAssemblies. In my machine it references 2.2.0 version of Microsoft.AspNetCore.Http.Abstractions.dll successfully. Hope it helps:)

If installing a nuget in a class library do I also have to add it to the client app?

I have a class library such as .NET Standard 2.0 that uses a nuget. I have multiple clients that use this class library. Will the client automatically get the required files from the class library references or do I need to install the same nugets used in class libraries in client apps that consume the library?
It depends on the nuget, generally in nuget's which are purely .net based won't be needed to be installed on the platform projects, for example, Json.net.
But let's say that you are using a nuget which interacts with the native api, under the hood, like Rg.Plugins.Popup, which lets you create UI basically which is not entirely only .NET thing, so it will be required to be installed on all the platforms.
There's really not a way that you can differentiate between them, but if you check the nuget's Github page, they would generally mention whether you need to install it on platform projects or not.
But you can assume that something which affects the UI would be needed to be installed on the platform project, whereas something which does nothing but pure logical processing would only be required to be installed to your .NET standard library.

Xamarin form: Does this give limitation access the libraries

I have a problem with these packages which I wanted to use on my Xamarin form using .net standard 2.0
Package 'ExifLib.PCL 1.0.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Package 'Microsoft.Bcl 1.1.6' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Package 'Microsoft.Bcl.Async 1.0.165' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Package 'Mobilist.AdvancedTimer.Forms.Plugin 1.0.1' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Package 'PCLStorage 1.0.2' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Package 'Rg.Plugins.Popup 1.0.4' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.
Does that mean I can't use this library any more?
Does that mean I can't use this library any more?
No, you should be able to use nearly all libraries that are PCL spec compliant inside of a .NET Standard 2.0 class library. You can checkout the .NET documentation to see list of PCL profiles with their supported platform and their corresponding .NET Standard supported version.
Package warning explanation
With .NET Standard 2.0 and the updated tooling in .NET Core SDK 2+ the .NET team wanted to make it easier to update or make use of .NET Standard libraries. The issue is that not all NuGet packages have been updated to support a version of .NET Standard. So they introduced a fallback targeting .NET Framework 4.6.1 which is nearly 100% compliant with .NET Standard (There are some API that are in the .NET Standard 2.0 spec that are not in .NET Framework 4.6.1 but they can be brought in via NuGet packages if required). So the warning you see is to inform you that the packages do not conform to a .NET Standard version you are targeting and as such may contain API's that are not executable in your runtimes making use of your .NET Standard 2.0 library.
Once you have tested that everything is working as expect you can add the NoWarn="NU1701" to your PackageReference in your csproj which will remove the warning. One thing to note adding NoWarn="NU1701" to a individual package does not remove the warning for dependencies. To remove those warning you must either include them as PackageReferences (via NuGet) or ignore NU1701 warning at a project level.
If you run into fallback issues you can adjust the target framework fallback via overriding the AssetTargetFallback in your csproj to something like:
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wpa81;</AssetTargetFallback>

Winmd build for a SDK using SQLite as a dependent library

I have a SDK written in C# targeting Win10 UWP apps.
It uses SQLite and works perfectly on C# client apps.
But can a C++/javascript app use my SDK with the SQLite dependency?
A winmd (windows runtime component build) would be required in case the SDK has to be UWP compatible since a UWP app can be in C#/C++/javascript/Visual basic.
I have posted this in msdn forums and they say i would need a windows runtime component for all the 3rd party dependencies for it to work.
Have already tried wrapper projects and wrapper winmd build, it does not work.
I am unable to find any winmd build for SQLite library.
Please advise on what can be done here.
Any help is really appreciated.
But can a C++/javascript app use my SDK with the SQLite dependency?
Yes, as in msdn forums said, you will need to wrapper in WinRT component universal apps.
Have already tried wrapper projects and wrapper winmd build, it does not work.
I don't know what blocks you, but you can refer to Writing a SQLite wrapper component for universal Windows apps, there are detailed steps you will need to follow, and samples you may have a look.
I tried various approaches to make this project work and found some success in the following:
Following is the project structure I made along with dependencies :
Client Application (in C++):
Wrapper winmd library.
Wrapper winmd library (in C#): (I generate a winmd component from this project)
My SDK project
My SDK project (in C#):
SQLite Net.
SQLite Net Async.
Newtonsoft JSON.
When I build the client application, I get the wrapperlibrary.winmd file but I dont get the corresponding dlls from the 3rd party dependencies in the output directory (SQLite and Newtonsoft). So i manually copied the required dlls to the output directory of the C++ application. Now it seems to work correctly, I can verify correct usage of the 3rd party libraries and my C# code. Presently I am just trying to make the setup work as a poc and worry about the packaging later.
The issue I now face is that my SDK also has some UI elements, so essentially compiled .xbf files for the "XAML" I have.
I have asked this question in another thread to not go off main topic here.

Resources