How to add nuget package in Xamarin studio - c#

I am completely new to xamarin studio. I am trying to add a nuget package. using the add packages dialogue appears to be working however I get an error:
Attempting to gather dependency information for package 'SidebarNavigation.1.9.0.3' with respect to project 'helloios', targeting '.NETPortable,Version=v4.0,Profile=Profile344'
Attempting to resolve dependencies for package 'SidebarNavigation.1.9.0.3' with DependencyBehavior 'Lowest'
Resolving actions to install package 'SidebarNavigation.1.9.0.3'
Resolved actions to install package 'SidebarNavigation.1.9.0.3'
For adding package 'SidebarNavigation.1.9.0.3' to project 'helloios' that targets 'portable40-net45+sl5+win8+wp8+wpa81'.
Install failed. Rolling back...
Package 'SidebarNavigation.1.9.0.3' does not exist in project 'helloios'
Package 'SidebarNavigation.1.9.0.3' does not exist in folder '/Users/********/Projects/helloios/packages'
Could not install package 'SidebarNavigation 1.9.0.3'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.0,Profile=Profile344', 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.
This is the github page for the package.
https://github.com/jdehlin/Xamarin-Sidebar
I tried to use different PCL profiles to no effect. I'm not sure how to determine which profile should be used.

The package targets only "Xamarin.iOS". You can't reference it in a PCL that targets more than that, since any other platform wouldn't be able to use it.
Either don't use a PCL, or restrict the PCL to "Xamarin.iOS".
Since this seems to be a UI component, you should reference it from your main project instead, and maybe expose some functionality through services to the PCL, if needed.

Related

Cannot update nuget package (PCL)

I'm getting this error when using maps in Android:
System.MissingMethodEsception: Method
'Xamarin.Forms.maps.Android.MapRenderer.OnCameraChange' not found.
And I've read that you can update the nugetpackage to fix the issue. However, I cannot install it due to this:
Could not install package 'TK.CustomMap 2.0.1'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile78', 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.
The updates of packages installs just find in iOS and Android but not for PCL. I've tried to remove all the packages and then tried to add TK.Customs nuget package but this same issue.
Also tried to install it on a fresh project and that installed just fine. Just cant get it to install on my old project.
Here is the whole error message when trying to update package:
Attempting to gather dependency information for package 'TK.CustomMap.2.0.1' with respect to project 'Vernamo', targeting '.NETPortable,Version=v4.5,Profile=Profile78'
GET https://api.nuget.org/v3/registration3-gz-semver2/tk.custommap/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/tk.custommap/index.json 175ms
Total number of results gathered : 29
Gathering dependency information took 232 ms
Summary of time taken to gather dependencies per source :
https://api.nuget.org/v3/index.json - 204.03 ms
Attempting to resolve dependencies for package 'TK.CustomMap.2.0.1' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'TK.CustomMap.2.0.1'
Resolved actions to install package 'TK.CustomMap.2.0.1'
Found package 'TK.CustomMap 2.0.1' in '/Users/holger/Downloads/Vernamo/packages'.
For adding package 'TK.CustomMap.2.0.1' to project 'Vernamo' that targets 'portable45-net45+win8+wp8'.
Install failed. Rolling back...
Package 'TK.CustomMap.2.0.1' does not exist in project 'Vernamo'
Executing nuget actions took 52 ms
Could not install package 'TK.CustomMap 2.0.1'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile78', 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.
The pre-release version (at least pre2) of TK.CustomMap supported all platforms (see here), anyway, as of pre3 (see here), obviously the support for all platforms was dropped in favor of .NET Standard (1.1 in this case).
The profile you are using in your PCL does not seem to be compatible with .NET Standard 1.1, hence NuGet fails to add the reference. You may try to switch to another profile (.NET 4.5.1 for example), but I don't know if that would help. Another option would be to migrate your projects to .NET Standard. It's kind of a stupid, repetetive task, but it's possible.

I Cant Install Microsoft.Identity.Client In Xamarin.Forms

I Try to Install Microsoft.Identity.Client Nuget to my Xamarin.Forms Project. But every time i try to install the package I always get this error message:
Could Not install package ' Microsoft.Identity.Client 1.0341221-alpha'. 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 iformation, conct the package author
What should I do here, I have already tried all version of the package, and try to install the package from Package Manager Console
The error is very clear, the NuGet does not contain any target platforms that are supported in your PCL profile 259.
You should migrate your PCL to a .NET Standard library, at least version 1.1 to consume the NuGet package in your shared code. Alternatively, you could abstract it away with an Interface and Dependency Injection, which probably will be more time consuming.

Could not install package 'System.Security.SecureString'

I couldn't install package 'System.Security.SecureString' in my PCL.
I tried some of the solutions online such as adding project.json to the PCL but nothing works
Here is the error log
Attempting to gather dependency information for package
'System.Security.SecureString.4.3.0' with respect to project
'TestProj', targeting '.NETPortable,Version=v4.5,Profile=Profile259'
GET
https://api.nuget.org/v3/registration1-gz/system.security.securestring/index.json
OK
https://api.nuget.org/v3/registration1-gz/system.security.securestring/index.json
144ms Total number of results gathered : 15 Gathering dependency
information took 496.15 ms Summary of time taken to gather
dependencies per source : https://api.nuget.org/v3/index.json - 172.87
ms Attempting to resolve dependencies for package
'System.Security.SecureString.4.3.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms Resolving actions to
install package 'System.Security.SecureString.4.3.0' Resolved actions
to install package 'System.Security.SecureString.4.3.0' Retrieving
package 'System.Security.SecureString 4.3.0' from 'nuget.org'. For
adding package 'System.Security.SecureString.4.3.0' to project
'TestProj' that targets 'portable45-net45+win8+wp8+wpa81'. Install
failed. Rolling back... Package 'System.Security.SecureString.4.3.0'
does not exist in project 'TestProj' Package
'System.Security.SecureString.4.3.0' does not exist in folder
'/Users/durai/Documents/BTFleet/BT Fleet/_git/DailyCheckApp/packages'
Executing nuget actions took 136.1 ms Could not install package
'System.Security.SecureString 4.3.0'. 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.
Any help in successfully installing the package is appreciated !
The System.Security API of .NET is not PCL friendly and therefore cannot be added in the PCL project.
But, it can be added in the other projects of the Xamarin solution - you can add that to the native projects like Android and iOS projects. And because you can add it there you can create the implementations on those projects and call those implementation via Dependency Service in your PCL.
The high level steps are:
1.) Create an interface in your PCL.
2.) Create a method in that interface that will be implemented in the Android or iOS projects.
3.) Add the Nuget package for System.Security.SecureString to your native project.
4.) Create a class in your native code that will implement that interface from the PCL.
5.) Call this code from your PCL via DependencyService.
For an example on how to do this, see this link.
It is lengthy and tedious but worth it.

Can't install Microsoft.ProjectOxford.Face NuGet into Xamarin Studio iOS project

I tried a lot, but I can't install Microsoft.ProjectOxford.Face NuGet into Xamarin Studio iOS project.
I got this error:
Could not install package 'Microsoft.ProjectOxford.Face 1.2.5.1'. 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 tried to update all packages, also Xamarin and still same problem. Only this package does not work - other like Newtonsoft.Json, Mircosoft.Net.HTTP and many other was installed correctly. I tried to install first Microsoft.BCL also Microsoft.BCL.Build and it also does not work.
Maybe you have any thoughts what can I do to make it work?
Unfortunately this is a problem with the Microsoft.ProjectOxford.Face 1.2.5.1 NuGet package itself. Whilst it has a portable class library (PCL) folder this does not map to a valid PCL profile:
portable-net45+wp80+win8+wpa81+aspnetcore50
If the aspnetcore50 part of that folder is removed then it would install into Xamarin.iOS. As it is, NuGet will not allow you to install it.
The only thing left you can do is unzip the NuGet package and try directly using the assembly. NuGet will not allow you to install it.
I believe there are plans to update the NuGet package to fix this, but that has not yet happened.

Why can't my PCL use System.Runtime?

I have a PCL that targets the following platforms:
.NET Framework 4.5
Windows 8
Windows Phone 8.1
I need to add a reference to System.Runtime because I want to use another package that depends on it. From what I can see, version 4.0.0 appears to include the target platforms mentioned above. However, when I try installing it via NuGet, I get this stack trace:
PM> Install-Package System.Runtime -Version 4.0.0
# ...
Install failed. Rolling back...
Package 'System.Runtime 4.0.0' does not exist in project 'PclDummy'
Package 'System.Runtime 4.0.0' does not exist in folder 'C:\Users\James\Documents\Visual Studio 2015\Projects\PclDummy\packages'
Install-Package : Could not install package 'System.Runtime 4.0.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.
Why does this happen if System.Runtime supports all of the platforms my PCL does?
that targets '.NETPortable,Version=v4.5,Profile=Profile111'
Be sure to distinguish between reference assemblies and runtime assemblies. To get your PCL project compiled, you only need reference assemblies. And you already have one for System.Runtime, it is located in the C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETPortable\v4.5\Profile\Profile111 directory on your machine. It is already referenced in your project so the package was correctly rejected.
These kind of crazy "but everybody already has this" Nuget packages come from the CoreCLR project. It is evolving rapidly right now with beta versions released at a very high rate. Which is one of the targets supported by Profile111, it supports an ASP.NET Core 5.0 target. Not one you listed in your question so you probably don't need it at all. But if you would then it would be that project that downloads this Nuget package. Which is entirely automatic, you don't ask for the packages explicitly.
Just stop trying to get it installed.
it seems that System.Runtime is not completely supported in version 4.5.
you can check it in the profile folder in following path:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile\Profile111
there is a list of supported assemblies and namespaces.

Categories