Error installing System.IdentityModel.Token.Jwt in Xamarin.Forms - xamarin.forms

I'm trying to use the System.IdentityModel.Token.Jwt NuGet package for my Xamarin.Forms app. When I try to add the package to my PCL, it installs in my Android and iOS projects, but I get the following error when adding it to the shared code project:
Could not install package 'System.IdentityModel.Tokens.Jwt 5.1.3'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.6,Profile=Profile44', 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.
Does anyone know how to get around this? I think it has to do with what my project targets but I've tried a few combinations and all of them have produced the same error, just with a different profile listed.

Unfortunately the System.IdentityModel.Tokens.Jwt 5.1.3 NuGet package only contains assemblies that support:
.NET Framework 4.5.1
.NET Standard 1.4
No portable class library profile supports .NET Standard 1.4. The highest they support is .NET Standard 1.2.
So unless you can find another NuGet package that does support portable class libraries you are left with trying to compile the Jwt source code for the portable class library profile you need, or converting your portable class library project into a .NET Standard project and target at least 1.4. You should be able to convert your portable class library project into a .NET Standard project in the project options.

Related

Error while installing nuget package nuget package Kentor.OwinCookieSaver

I have ASP.NET MVC 5 application with .NET 4.5.1. The application is having issue as described in this SO post.
So as per the suggestion i am trying to install https://github.com/Sustainsys/owin-cookie-saver nuget package However i am getting error
Severity Code Description Project File Line Suppression State
Error Could not install package 'Kentor.OwinCookieSaver 1.1.1'. You
are trying to install this package into a project that targets
'.NETFramework,Version=v4.5.1', 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. 0
any idea?
Right now, the ASP.NET MVC 5 app you have is targeting .NET 4.5.1. No surprise there. The error says "You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.1', but the package does not contain any assembly references or content files that are compatible with that framework."
The highlighted line indicates that the package you are trying to install is not built for .NET 4.5.1. I went ahead and downloaded the package itself (from NuGet.org). The package is currently targeting .NET 4.5.2. So if you change your target framework to .NET 4.5.2 and try to install, you will find it works out for you.
Ideally, packages available to the public would be built for a wider range of Target Frameworks but occasionally I do run into this. If you run into this again, go grab the package from the previous link (see the Manual Download on the right hand side of the page). Open up the .nupkg using 7-zip and open up the lib folder. There you will find what frameworks it is targeting and can adjust accordingly (or decide to try another package if you can't change).

Unable to install Nuget package in my Xamarin Cross Platform Application

I am developing a xamarin cross platform that is composed of following projects
1)Portable
2)IOS
3)Android
4)UWP
I am facing an issue while installing NuGet package for the xamarin portable project. Actually the NuGet that i am trying to install is targeted on .net Framework version 4.5.2. So we need the .net Version 4.5.2 or higher in our application in order to install this library. However when i try to change target framework version in my project properties to 4.6 then also i am facing the compatibility error that given package is not compatible with .net 4.5.
So what is the correct way that to set the .Net framework version in the project so that i can install it any project.
I have also referred to this doc by Microsoft
https://learn.microsoft.com/en-gb/dotnet/standard/net-standard#comparison-to-portable-class-libraries
that shows compatibility matrix.
I think it is related to .net standard 2.0. use these links
https://xamarinhelp.com/upgrade-pcl-net-standard-class-library/
https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-standard-2-0/

Need to build Roslyn Analyzer targeting .NET Standard \ Core rather than .NET Portable

I'm using default Roslyn SDK templates that came with Visual Studio 2017. The projects they create target .NET Framework Portable. I'm assuming Roslyn extensibility projects can target .NET Standard \ Core instead of Portable and I'm looking for templates or a sample of Roslyn Analyzer \ Refactoring project that I could study.
Sample of converted analyzer from default analyzer template is available here. There is original analyzer for comparison along with TestAnalyzerStandard which targets .NET standard.
Steps to make it work:
Create new .NET Standard library
Library must target .NET Standard 1.3. This is required if you wish to run analyzer as extension inside VS (extensions target .NET 4.6). Mapping between standard versions and full framework versions is available here. Also if you try to target lower version than 1.3, you will not be able to include required analyzer packages.
Add nuget package for Microsoft.Composition latest version. This is needed by Microsoft.CodeAnalysis.CSharp.Workspaces. If you try to add workspaces first, you will get error that referenced composition package is not compatible.
Add nuget package for Microsoft.CodeAnalysis.CSharp (I'm using latest 1.* version)
Add nuget package for Microsoft.CodeAnalysis.Csharp.Workspaces (version should match the version of Microsoft.CodeAnalysis.CSharp).
At this point you can copy code from portable project and build it. There should be no errors (you may have to close and reopen solution if VS is still displaying red squiggles).
To make VS extension work, just open source.extension.vsixmanifest, go to assets tab and change reference to .NET standard library
To create .nuget package just execute nuget pack Diagnostic.nuspec .. Diagnostic.nuspec is valid for Nuget 2.x. If you are using nuget via package management console in VS 2017 you will have to change <file src="*.dll" ..." to <file src="bin\*\netstandard1.3\*.dll" ....
Those steps are result of my experimentation with analyzers (I previously played with creating DLL which targeted full framework instead of being portable library). They are not by any means official.
I started working on a new Roslyn project and built things one by one instead of using template. https://github.com/IKoshelev/Roslyn.AutoLogging/commit/1f88e3e49141e0fa425c51fdcb3457a7c3d6dcaa
I managed to have the following targeting:
Refactoring project - .NET Standard 1.3 (this .dll will be distributed, version kept to minimum)
UnitTests project - .NET Core 2.0
VSIX project - .NET Framework 4.6 (I believe, only full Visual Studio supports VSIX, so that is okay)
Update Versioning of Roslyn is a bit more complicated right now, i.e. if you want to use your extensions with Visual Studio 2015 you will have to use PCL libraries. More info at the end of this article article on Roslyn

Using SQLite with Xamarin.Forms cross-platform project

I have used Visual Studio 2017 Community edition to create a plain vanilla cross platform PCL project, and would like to use SQLite. The only thing done to the project(s) was the use of Nuget to update all packages that needed updating.
Then, following the instructions on the Xamarin website at
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/databases/
I used Nuget to install sqlite-net-pcl,
It all seemed to work OK, except at the end the following error appears.
I presume the documentation is slightly dated. Should I change the target .NET framework. If so, to what?
As of v1.3 SQLite-Net-PCL is actually no longer a PCL, it is a .Net standard library.
You need to install version 1.2.0 of the NuGet package to use it inside a PCL - from the nuget package manager you can select a version so install v1.2.0 into all your projects.
The library above worked OK as a PCL library, but what I disliked was that the platforms were split out in to separate DLLs so you had a different dependency for each platform.
This library is for .NET Standard and only has a single DLL for all platforms:
https://github.com/MelbourneDeveloper/SQLite.Net.Standard
It does not support the ORM like functionality in the above library though.

Cannot use DynamicObject in net standard 1.6 class library project

Refer to the screenshot below, I need to use DynamicObject in .net standard 1.6 library project.
However, I cannot add any additional dependencies by right click the Dependencies and Add Reference in Visual Studio 2017 Enterprise (15.2).
Does anyone know how to use DynamicObject in .net standard class library project targeting netstandard 1.6?
You need to add the System.Dynamic.Runtime NuGet package for the type to become available in the System.Dynamic namespace. In netstandard2.0, it will be available automatically.
dotnet add package System.Dynamic.Runtime

Resources