我正在构建一个 Xamarin 应用程序,并且我的共享代码位于面向 .NET 4.5 框架的 PCL 中。我还有一个库,它基本上在另一个库中实现了我的 Xamarin 应用程序的服务访问层,该库面向 .NET 标准 2.0。
问题是,当我尝试引用后者时,Visual Studio 给出以下错误:
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 框架。任何见解将不胜感激。
最佳答案
不,支持 .net 标准 2.0 的 .net 框架最低版本是 .net 4.6.1(使用 vs 2017.3+ 的 .net core 2.0 工具)。无论您使用什么工具,.Net 4.7.1 都真正支持 .net 标准 2.0。
.net standard 2.0拥有庞大的API接口(interface),Entity Framework Core 2.0和asp.net core 2.0都是基于.net standard 2.0 api开发的。
请注意,pcl 配置文件 111 代表 .net 4.5 和 Windows 8.1,它们共同支持 .net 标准 1.1。
由于最新的 xamarin forms 2.5 支持 .net standard 2.0,我建议您停止使用 PCL 项目,并在各处使用 .net standard 2。
使用 xamarin 表单查看我的待办事项示例应用程序,该应用程序使用 .net standard 2 和 ef core 2 + SQL lite 面向 Android 和 iOS,网址为 https://github.com/ysmoradi/ToDo
您还可以定位 .net 框架库的 nuget 包,例如 https://github.com/davideicardi/DynamicExpresso它适用于移动设备,但仅针对 .net 框架。以前您无法使用它,现在可以。
如果你想将 pcl 库的 nuget 包添加到你的项目中,请查看 https://github.com/ysmoradi/ToDo/blob/master/src/ToDo/ToDo.csproj#L5
因此,更新到 xamarin forms 2.5,将您的 pcl 替换为 .net standard 2.0,然后就可以开始了:)
Visual studio 2017.5 使用 .net 标准而不是 pcl 创建项目,因为这是 future 。
关于.net - 添加对面向 .NET 标准 2.0 的类库的引用到面向 .NET 标准 4.5 的 Xamarin PCL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47362801/