I am building a Xamarin application and I have my shared code in a PCL which targets the .NET 4.5 framework. I also have a library, which basically implements the service access layer of my Xamarin application in another library, which targets .NET standard 2.0.
The problem is that when I try to reference the latter, Visual Studio gives me the following error:
Project [Service access library] targets '.NETStandard,Version=v2.0'. It cannot be referenced by a project that targets '.NETPortable,Version=v4.5,Profile=Profile111'.
I don't understand why, since, from what I understand, .NET standard stands on a lower abstraction level than the .NET 4.5 framework. Any insight would be much appreciated.
No, minimum version of .net framework which supports .net standard 2.0 is .net 4.6.1 (with .net core 2.0 tooling of vs 2017.3+). .Net 4.7.1 has true support for .net standard 2.0 no matter what tooling you use.
.net standard 2.0 has a large API surface, entity framework core 2.0 and asp.net core 2.0 are developed based on .net standard 2.0 apis.
Note that pcl profile 111 stands for .net 4.5 and Windows 8.1 and they support .net standard 1.1 in common.
As latest xamarin forms 2.5 supports .net standard 2.0, I recommend you to stop using PCL projects, and use .net standard 2 everywhere.
Checkout my to do sample app with xamarin forms which targets both android & iOS using .net standard 2 and ef core 2 + SQL lite at https://github.com/ysmoradi/ToDo
You can also target nuget packages of .net framework libraries such as https://github.com/davideicardi/DynamicExpresso It works on mobile, but it targets .net framework only. You weren't able to use that before, now you can.
If you want to add nuget packages of pcl libraries to your project, take a look at https://github.com/ysmoradi/ToDo/blob/master/src/ToDo/ToDo.csproj#L5
So, update to xamarin forms 2.5, replace your pcl with .net standard 2.0 and you're good to go :)
Visual studio 2017.5 creates projects using .net standard instead of pcl as this is a future.