Xamarin.Forms + Xamarin.ios Entityframework Core 2.1.1构建错误

时间:2018-08-08 14:52:57

标签: xamarin.forms xamarin.ios .net-standard-2.0 entity-framework-core-2.1 system.memory

我正在使用带有Xamarin.forms .NetStandard 2.0版本的Microsoft.EntityframeworkCore.Sqlite版本2.1.1的Xamarin.ios应用程序。我无法在iPhone上构建应用程序,出现以下错误:

  

MTOUCH:错误MT3001:无法自动执行程序集'project_name / iOS / obj / iPhone / Debug / device-builds / iphone10.2-11.0.2 / mtouch-cache / Build / Microsoft.EntityFrameworkCore.dll'(MT3001 )(project_name.iOS)

任何人都可以帮助我解决该错误吗?我尝试将entityframework版本降级到2.0.0,还将Microsoft.extension。*版本降级到2.0.0。

链接器行为:不仅链接/链接SDK SDK版本:11.0

1 个答案:

答案 0 :(得分:0)

在我正在从事的项目中实现EntityFrameworkCore时,我遇到了类似的错误。对我来说,解决方案是将文件添加到我的iOS项目中,并拥有这些内容。另外,我目前正在运行Microsoft.EntityFrameworkCore.Sqlite 2.0.2版本,没有问题。

<?xml version="1.0" encoding="utf-8" ?>
<linker>
    <!-- LinkDescription.xml. File added to iOS project by @cwrea for adaptation to EF Core.

    Prevents runtime errors when reflection is used for certain types that are not otherwise referenced
    directly in the project, and that would be removed by the Xamarin linker.

    These kinds of runtime errors do occur in particular when using Entity Framework Core on iOS. EF Core's
    query parser does reference certain .NET methods _only_ via reflection, and it is those reflection-only
    instances that we need to guard against by ensuring the linker includes them. For the curious, search
    for mentions of "GetRuntimeMethod" at https://github.com/aspnet/EntityFramework. Use of EF Core more
    advanced than this sample may require additional types/methods added to those below.

    Include the following in the project build settings under "Additional mtouch arguments":
      [hyphen][hyphen]xml=${ProjectDir}/LinkDescription.xml

    There is supposed to be a "LinkDescription" build action for this linker config file so the step above
    shouldn't be necessary, but at time of writing Visual Studio 2017 for PC doesn't show that build action
    in iOS projects, even though it is an option within iOS projects on Visual Studio 2017 for Mac.
    -->
    <assembly fullname="mscorlib">
        <type fullname="System.String">
            <method name="Compare"></method>
            <method name="CompareTo"></method>
            <method name="ToUpper"></method>
            <method name="ToLower"></method>
        </type>
    </assembly>
    <assembly fullname="System.Core">
        <type fullname="System.Linq.Expressions.Expression`1"></type>
        <type fullname="System.Linq.Queryable"></type>
    </assembly>
</linker>

您还需要将文件Build Action设置为 LinkDescription 。另外,您无需将该文件复制到输出目录。仅在构建期间使用。

iOS项目的项目设置中,您需要将-xml = $ {ProjectDir} /LinkDescription.xml 放在{ {1}}。

希望这会有所帮助!