Xamarin.iOS 项目:CS1703:已导入多个具有相同标识的程序集

2024-05-16

我有一个使用 .NET Standard 2.0 的跨平台(iOS 和 Android)Xamarin 解决方案。该解决方案是由 Visual Studio 2017 构建的(我已经尝试了当前版本和预览版本)。 Forms 和 Android 项目构建良好。但是,iOS 无法构建,并出现以下错误:

1>CSC:错误CS1703:已导入多个具有相同标识的程序集:'C:\Users\newuser.nuget\packages\system.reflection.emit\4.3.0\ref\netstandard1.1\System.Reflection.Emit。 dll' 和 'C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\ReferenceAssemblies\Microsoft\Framework\Xamarin.iOS\v1.0\Facades\System.Reflection.Emit.dll'。删除重复的引用之一。

我已经尝试了许多解决方法,如下所述:

奥伦代码 https://oren.codes/2017/04/23/using-xamarin-forms-with-net-standard-vs-2017-edition/

www.hanselman.com https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx

github.com/NuGet https://github.com/NuGet/Home/issues/4581

不幸的是,这些建议都不起作用。我还尝试将 System.Reflection.Emit nuget 包直接添加到表单和/或直接添加到 iOS 项目。这也行不通。请注意,最初,解决方案中的任何内容都没有直接引用 System.Reflection.Emit 包。它被以下明确引用的 nuget 包拉入:

  • Acr.DeviceInfo (5.0.5)
  • 阿卡瓦什 (6.0.0-alpha0038)
  • 自动映射器 (6.2.2)
  • Microsoft.Identity.Client (1.1.1-preview0040)
  • Newtonsoft.Json (10.0.3)

最后,我尝试在包控制台中使用 update-package -reinstall 命令来重新安装 iOS 项目的所有包。这也行不通。

- 更新

澄清一下,Xamarin Forms 或 Xamarin iOS 项目都没有直接引用 System.Reflection.Emit。该包作为其他 nuget 包的依赖项,仅从安装到 Xamarin Forms 项目中的包中提取。我已确认 Nuget 引用的所有依赖项都使用相同的版本。请参阅这些屏幕截图:

在我看来,问题(如错误所述)是 Visual Studio 安装了旧版本的 System.Reflection.Emit 。但是,我找不到忽略它并使用 System.Reflection.Emit 版本的方法。正如我上面所说,我尝试在 Xamarin.iOS 项目中使用 project.json 文件,并手动忽略,但这不起作用。

还有其他人有什么想法吗?

顺便说一句,我注意到这个错误对于 Xamarin 来说仍然是开放的。

Xamarin 错误 https://bugzilla.xamarin.com/show_bug.cgi?id=54139


感谢 @DirkWilhem 在 Xamarin 论坛网站上的回答,成功解决了这个问题。

基本上,将其添加到您的 Xamarin iOS 项目中.csproj文件,以及其他 PackageReference 节点:

<PackageReference Include="System.Reflection.Emit">
  <Version>4.3.0</Version>
  <ExcludeAssets>all</ExcludeAssets>
</PackageReference>

当然你需要先确保nuget包已经添加到iOS包中。

Xamarin 论坛讨论 https://forums.xamarin.com/discussion/comment/318851#Comment_318851

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Xamarin.iOS 项目:CS1703:已导入多个具有相同标识的程序集 的相关文章

随机推荐