向以.NET Standard 4.5为目标的Xamarin PCL添加针对.NET标准2.0的类库的引用 [英] Add a reference to a class library which target .NET standard 2.0 to a Xamarin PCL which targets .NET Standard 4.5

查看:125
本文介绍了向以.NET Standard 4.5为目标的Xamarin PCL添加针对.NET标准2.0的类库的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建Xamarin应用程序,并且我的共享代码位于针对.NET 4.5框架的PCL中.我还有一个库,该库基本上在另一个针对.NET标准2.0的库中实现了Xamarin应用程序的服务访问层.

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.

问题在于,当我尝试引用后者时,Visual Studio给我以下错误:

The problem is that when I try to reference the latter, Visual Studio gives me the following error:

项目[服务访问库]目标为'.NETStandard,Version = v2.0'.面向'.NETPortable,Version = v4.5,Profile = Profile111'的项目不能引用它.

Project [Service access library] targets '.NETStandard,Version=v2.0'. It cannot be referenced by a project that targets '.NETPortable,Version=v4.5,Profile=Profile111'.

我不明白为什么,因为据我了解,.NET标准的抽象级别低于.NET 4.5框架.任何见识将不胜感激.

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.

推荐答案

否,支持.net标准2.0的.net框架的最低版本是.net 4.6.1(使用.net core 2.0工具,而vs. 2017.3+).无论您使用哪种工具,.Net 4.7.1都对.net标准2.0拥有真正的支持.

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标准2.0具有较大的API表面,基于.net标准2.0 api开发了实体框架核心2.0和asp.net核心2.0.

.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.

请注意,pcl配置文件111代表.net 4.5和Windows 8.1,它们共同支持.net标准1.1.

Note that pcl profile 111 stands for .net 4.5 and Windows 8.1 and they support .net standard 1.1 in common.

由于最新的xamarin形式2.5支持.net标准2.0,所以我建议您停止使用PCL项目,并在所有地方使用.net标准2.

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.

检出我的应用程序,以同时针对android& amp;在 https://github.com/ysmoradi/ToDo

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

您还可以定位.net框架库的nuget包,例如 https://github.com/davideicardi/DynamicExpresso 可在移动设备上使用,但仅针对.net框架.您以前无法使用它,现在可以使用.

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.

如果要将pcl库的nuget包添加到项目中,请查看

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

因此,更新到xamarin Forms 2.5,用.net standard 2.0替换您的pcl,您就很好了:)

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使用.net标准而不是pcl创建项目,因为这是未来.

Visual studio 2017.5 creates projects using .net standard instead of pcl as this is a future.

这篇关于向以.NET Standard 4.5为目标的Xamarin PCL添加针对.NET标准2.0的类库的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆