首页 > 解决方案 > Unity使用外部dll“具有相同名称的多个预编译程序集”

问题描述

我有一个“共享”项目,我在我的客户端(统一)和我的服务器(C# 服务器)之间共享代码

这两个项目都需要 Newtonsoft.Json.dll


当我编译 Shared.dll 并将其放在 Unity 的 Resources 文件夹中(因此它包含在构建中)时,我收到此错误:

PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included or the current platform. Only one assembly with the same name is allowed per platform. Assembly paths: 
Assets/Resources/Shared/Newtonsoft.Json.dll
C:/Users/rotmg/Documents/GitHub/AG-LNL/AG-LNL-Client/Library/PackageCache/com.unity.nuget.newtonsoft-json@2.0.0-preview/Runtime/Newtonsoft.Json.dll

我意识到这是 Unity 对 Newtonsoft.Json 的依赖和我的 Shared.dll 之间的冲突。


这个答案:

https://answers.unity.com/questions/1697304/how-to-resolve-multiple-precompiled-assemblies-err.html

说要使用“将所有依赖项合并到一个 .dll 中”

因此,我尝试使用 Costura.Fody 构建一个捆绑所有依赖项的单个 .dll,但随后我收到一条错误消息,提示我应该添加对 Shared 具有的依赖项的引用。(NLog、BouncyCastle 等)


我该如何解决这个冲突?

标签: c#unity3d

解决方案


在我的情况下,从 Unity 2020.3.8f1 更新到 2020.3.17f1 并将 com.unity.collab-proxy 包从 1.3.9 更新到 1.7.1 后,它得到了依赖项 com.unity.nuget.newtonsoft-json,这与我手动导入的冲突Assets 文件夹中的 JsonDotNet 包。

在此处输入图像描述

在此处输入图像描述

从 Assets 文件夹中删除我手动导入的 JsonDotNet 包有帮助。删除关闭 Unity 后,删除文件夹YouProjectFolder\Library\PackageCacheYouProjectFolder\Library\ScriptAssemblies重新启动 Unity。

在此处输入图像描述


推荐阅读