Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Xamarin platforms projects unable to resolve NuGet dependencies

$
0
0

I'm struggling to understand why I sometimes stumble into this situation with Xamarin platform apps not being able to resolve the NuGet indirect dependendencies from its shared (.NET Standard) project.

This was the situation:

I extended upon a cross platform (iOS, Android and UWP) NuGet package that I've built and deployed. The new feature required a new dependency to System.IdentityModel.Tokens.Jwt for the shared (.NET Standard) code library project. System.IdentityModel.Tokens.Jwt, in turn, has dependencies for Microsoft.IdentityModel.Tokens and Microsoft.IdentityModel.JsonWebTokens.

I build the code libraries; the .NET Standard 2.0 (shared) code lib and the three platform libs for iOS, Androind and UWP. All is good so I update my .nuspec and add System.IdentityModel.Tokens.Jwt to the <group targetFramework=".NETStandard2.0"> sub section of <dependencies> and pack the .nuget.

Next, to ensure everything works, I "deploy" the .nuget to a local folder (that I have set up as a nuget source for testing purposes) and then upgrade the NuGet references for my four test app projects (.Net Std, iOS, Android and UWP). The shared .Net Std lib project builds fine so I try building one of the platform ones, like the Android app. I now get this error:

Can not resolve reference: `Microsoft.IdentityModel.Tokens`, referenced by `(my package)`

I check the Android app project's project.assets.json file and here's the nuget output:

"(my package name)": {"type": "package","dependencies": {"Xamarin.Forms": "4.0.0"        },"compile": {"lib/MonoAndroid10/(my package name).Android.dll": {},"lib/MonoAndroid10/(my package name).dll": {}        },"runtime": {"lib/MonoAndroid10/(my package name).Android.dll": {},"lib/MonoAndroid10/(my package name).dll": {}        }      },

The thing is, (my package) has depenencies to other packages as well, other than System.IdentityModel.Tokens.Jwt, such as Xamarin.Essentials and System.Text.Json. They, in turn, have dependencies to other NuGets and so on. For some reason, this doesn't seem to be a problem at all. From what I've read (https://docs.microsoft.com/en-us/nuget/concepts/dependency-resolution) Visual Studio figures out all the dependencies and builds a dependency graph which is then flattened and written to project.assets.json of each project. Why is it some (most, apparently) packages can be fully resolved while others cannot?

I "solved" the problem by simply adding all the troublesome references directly into each platform target secion of the .nuspec file but I can't figure out why this should even be necessary.

Anyone?


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>