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

查看:118
本文介绍了如何在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' is defined in an assembly that is not referenced. Consider adding a reference to assembly System.Runtime,版本= 4.0.20.0,区域性=中性,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 Library"项目中将不起作用.它也不适用于我自己的任何以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一起使用,您需要手动将对System.Runtime的引用添加到* .csproj文件中.此参考在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天全站免登陆