类型“Memory<T>”同时存在于“System.Memory 4.0.1.0 和 mscorlib 2.0.5.0”中

Sof*_*ion 6 xamarin.ios

我很难解决这个新问题。
它仅在编译时出现在解决方案的 xamarin.ios 项目上。
xamarin.android 项目编译正常。

我没有引用 system.memory 而是 netstandard 2.0 项目。
直到最近才编译得很好。

这是 xamarin.ios 工具中的已知问题吗?有什么解决方法吗?

我试过了:

  • 谷歌搜索
  • 将system.memory nuget添加到ios项目中
  • 删除 bin/obj/.vs 文件夹,清理/重建

我很干。

Sof*_*ion 2

我在这里找到了解决方案!

在你的ios项目文件末尾添加:

  <Target 
    Name="VS16_RemoveSystemMemory" 
    BeforeTargets="FindReferenceAssembliesForReferences" 
    Condition="'$(MSBuildVersion)' &gt;= '16.0'">
    <ItemGroup>
      <_ReferencePathToRemove 
        Include="@(ReferencePath)" 
        Condition="'%(ReferencePath.NuGetPackageId)'=='System.Memory'" />
      <ReferencePath Remove="@(_ReferencePathToRemove)" />
    </ItemGroup>
    <Message Text="Removing System.Memory for VS 2019 compatibility" Importance="high"/>
  </Target>
Run Code Online (Sandbox Code Playgroud)

它神奇地编译了!
我不知道这个 nuget 依赖项来自哪里,但它不是来自我的代码,它来自第三方 nuget,很可能来自 Google 的。