如何在 xamarin iOS 中使用 netstandard 库? [英] How to use netstandard libs in xamarin iOS?

查看:32
本文介绍了如何在 xamarin iOS 中使用 netstandard 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次我添加对仅 netstandard 库的引用时,我都会收到以下错误.专门针对 xamarinios10 的库工作正常.

Every time I add a reference to netstandard only library I get following error. Libs that specifically target xamarinios10 works just fine.

错误 CS0012:类型 System.Object' 在未引用的程序集中定义.考虑添加对程序集的引用System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

error CS0012: The type System.Object' is defined in an assembly that is not referenced. Consider adding a reference to assemblySystem.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

例如,将 AutoMapper 库添加到新的iOS 库"项目不起作用.它也不适用于我自己的任何面向 netstandard 的 NuGet 包.

For example adding AutoMapper library to fresh "iOS Library" project does not work. It also does not work for any of my own NuGet packages targeting netstandard.

推荐答案

要使 .NET Standard 包与 Xamarin iOS 配合使用,您需要手动向 *.csproj 文件添加对 System.Runtime 的引用.此参考在 Xamarin Studio 中突出显示为无效,但项目可以编译并在设备和模拟器上运行.例如,为了使最简单的应用程序工作,我最终在我的 csproj 中拥有它

To make .NET Standard package work with Xamarin iOS you need to manually add reference to System.Runtime to your *.csproj file. This reference is highlighted in Xamarin Studio as invalid but project compiles and works on device and in simulator. For example to make simplest possible app work I end up having this in my csproj

<ItemGroup>
  <Reference Include="System" />
  <Reference Include="System.Xml" />
  <Reference Include="System.Core" />
  <Reference Include="Xamarin.iOS" />
  <Reference Include="System.Runtime" />
</ItemGroup>

注意底部的 System.Runtime 引用.

Note System.Runtime references at the bottom.

这篇关于如何在 xamarin iOS 中使用 netstandard 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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