将对面向 .NET Standard 2.0 的类库的引用添加到面向 .NET Standard 4.5 的 Xamarin PCL [英] Add a reference to a class library which target .NET standard 2.0 to a Xamarin PCL which targets .NET Standard 4.5

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

问题描述

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

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 standard 2.0 API 面很大,entity framework core 2.0和asp.net core 2.0都是基于.net standard 2.0 apis开发的.

.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 forms 2.5 支持 .net standard 2.0,我建议您停止使用 PCL 项目,并在任何地方使用 .net standard 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 和iOS 使用 .net 标准 2 和 ef core 2 + SQL lite 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 包添加到您的项目中,请查看 https://github.com/ysmoradi/ToDo/blob/master/src/ToDo/ToDo.csproj#L5

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 表单 2.5,用 .net 标准 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 2.0 的类库的引用添加到面向 .NET Standard 4.5 的 Xamarin PCL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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