Cannot update nuget package (PCL) - c#

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.

Related

nuget not resolving dependency using what specified in nuget package for Microsoft.Extensions.Logging

Background:
I have created a class library for .net core (targetting v2.2), and I have a .net core application as well (targetting v2.2).
I am trying to export the library as nuget package and install it in my application.
Here is the dependencies for my library
I am able to export it as nuget package and for now I am storing it in local nuget repo.
But when I try to install this library package in my application it's not getting installed due to package version conflict for Microsoft.Extensions.Logging. Here's package manager console output.
Issue:
I have specified the exact version for Microsoft.Extensions.Logging i.e. [2.2.0] as we could confirm that in the screenshot showing dependency for my library, then why it's getting resolved to version 3.0.0?
How could I resolve this issue?
Details about the environment:
NuGet product used (Package Manager Console): Package Manager Console Host Version 5.3.1.6268
VS version (if appropriate): Microsoft Visual Studio Community 2019 Version 16.3.8
OS version (i.e. win10 v1607 (14393.321)): Windows 10 Enterprise Version: 1809
How could I resolve this issue?
To resolve the strange behavior in your side, you should clean the nuget cache before installing that package in your current project.
(To make sure the cache is cleaned up, I suggest you go %userprofile%\.nuget\packages to check if there exists Com.lib folder within the Packages folder)
I have specified the exact version for Microsoft.Extensions.Logging
i.e. [2.2.0] as we could confirm that in the screenshot showing
dependency for my library, then why it's getting resolved to version
3.0.0?
I think the one(Com.Mylib) you want to install is not the first one you pack. I mean that you may actually build and pack several different Com.Mylib package with different content. And all of their names is Com.lib.1.0.0.nupkg.
Nuget stores all nuget cache in %userprofile%\.nuget\packages. So if I once install one PackageA in any project. The cache of PackageA is stored there. And if I open a new project trying to install the PackageA with same version(1.0.0), it actually installs the one from cache. So we will meet this strange behavior:
Nuget can recognize the Com.lib package depends on other 2.2.0 packages. But when it tries to install that package, it finds the package has existed in cache. Then he tries to install the one from cache, and I guess content of the one in cache is different from your latest one, then the issue occurs.
Suggestions:
1.When developing locally, use project reference instead of Nuget packages.
2.If you need to test the nuget package every time after packing, please make sure the package version has increased.(1.0.0=>1.0.1=>1.0.3... or beta-1.0.12, preview-xxx)
3.If you have special reason do use same version 1.0.0, please clean the cache to avoid previous cache affects current project.
Hope all above helps :)

Nuget.exe and NuGet Package Manager resolve different dependencies

I want to install OPCFoundation.NetStandard.Opc.Ua version 1.4.355.26 (and all of its dependencies) to an offline machine. My online and offline machines are running Visual Studio 2019 16.1.3.
When I install OPCFoundation.NetStandard.Opc.Ua version 1.4.355.26 using the NuGet Package Manager, it installs many dependencies, including Libuv.1.10.0. See screenshot:
When I download the same package for offline installation, nuget.exe fetches Libuv.1.9.2. See screenshot:
C:\Users\cstankevitz\Downloads>nuget.exe install OPCFoundation.NetStandard.Opc.Ua
Feeds used:
https://api.nuget.org/v3/index.json
C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
Installing package 'OPCFoundation.NetStandard.Opc.Ua' to 'C:\Users\cstankevitz\Downloads'.
GET https://api.nuget.org/v3/registration3-gz-semver2/opcfoundation.netstandard.opc.ua/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/opcfoundation.netstandard.opc.ua/index.json 558ms
Attempting to gather dependency information for package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26' with respect to project 'C:\Users\cstankevitz\Downloads', targeting 'Any,Version=v0.0'
Gathering dependency information took 16.89 sec
Attempting to resolve dependencies for package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26'
Resolved actions to install package 'OPCFoundation.NetStandard.Opc.Ua.1.4.355.26'
Retrieving package 'Libuv 1.9.2' from 'nuget.org'.
...
Of course, when I bring the downloaded packages to my offline machine and install them using Visual Studio 2019 NuGet Package Manager, the install fails because the Libuv.1.10.0 is not available.
How can I get nuget.exe (or any other tool) to download the correct packages needed by NuGet Package Manager for offline installation?
Here is how I installed the correct dependencies to my offline system:
On the online system
Fetch the source of https://github.com/StuffOfInterest/NuGetDependencyDownloader
Edit PackageTools.cs and modify the function GetRangedPackageVersion so that it contains the code below. This is needed to fix a "bug" in which older packages are not downloaded when newer packages are available -- but the older packages will be needed in Step 9 below.
Compile and run NuGetDependencyDownloader to download the package and its dependencies
Copy the packages to an external drive
On the offline system
Copy the packages to your offline system (c:\Work\2019-07018 Nuget Offline\ in my example)
Edit options for Nuget Package Manager | Package Sources. Add a source that points to the directory used in step 5. Specify Local Package Source Screenshot
Run Nuget Package Manager.
Specify the Package source that you created in step 6. Specify package source screenshot
Install your package
Notice that it appears to install but nothing is actually happening. It is trying to contact something online (which will fail after a long timeout). This is repeated for every dependency. Speed up the failure by disconnecting all of your interfaces (unplug cables, etc).
private IPackage GetRangedPackageVersion(IQueryable<IPackage> packages, IVersionSpec versionSpec)
{
packages = packages.Where(o => o.Version == versionSpec.MinVersion);
IPackage package = packages
.OrderByDescending(o => o.Version)
.FirstOrDefault();
return package;
}
If you look at the output of the Preview Changes dialog in VS, all the Microsoft.AspNetCore packages are version 2.0.1, whereas running nuget.exe, it got versions 1.1.x. If you look at OPCFoundation.NetStandard.Opc.Ua on nuget.org and expand the dependencies, you see it has dependencies on the 1.1 packages for net46 and netstandard2.0, but 2.0 dependencies for netstandard2.0.
From this I can deduce that your project is using netcoreapp2.0, netstandard2.0, or above, whereas nuget.exe is probably using some .NET Framework for dependencies.
As for ways to get the same packages that your project actually uses, I've answered this question several times in the past and I usually link to the first time I answered it

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.

Targetting a different package version based on build profile

I've got a class library that till today was for .NET 4.5, now I've been asked to port it to .NET 40 but I've got some difficulies. I've followed this approach
and it works for the nuget packages that
but using this approach I get an error when going to Manage Nuget Packages telling
What's the most clean way to target different .NET framework version without loosing nuget package manager?
UPDATE #1
I've this version of nuget package manager
The error message caused by the duplicate packages listed in packages.config file. Because the Manager NuGet Packages window will read the packages.config file to list installed packages in your project and manage them.
For your situation, please check whether the packages in your project could compatible with both of .NET 4.5 and .NET 4.0. If yes, you need not to use two version packages in one project. You just need to change the project .NET Framework through Project -> Properties -> Application -> Target Framework.
If the installed packages version could not compatible with .NET 4.5 and .NET 4.0 at the same time, and you still want to use the Manager NuGet Packages, I suggest you do with below manual operation: Comment out one version of the packages in packages.config file and then open Manager NuGet Packages. After using Manager NuGet Packages, please uncomment the version that commented before.

How to add nuget package in Xamarin studio

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.

Categories