Unity“多个同名预编译程序集”使用外部dll

Ald*_*lde 5 c# unity-game-engine

我有一个“共享”项目,我在我的客户端(统一)和我的服务器(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
Run Code Online (Sandbox Code Playgroud)

我意识到这是 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 等)


我该如何解决这个冲突?

Mik*_*ail 14

就我而言,从 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。

在此输入图像描述

  • 这是一种非常危险的方法,可能会破坏您的整个项目。 (5认同)

Omi*_*ast 5

基于这个答案: https://www.gitmemory.com/issue/juicycleff/flutter-unity-view-widget/414/859018825

最好的方法是导入没有 JsonDotNet 文件夹的项目或在导入之前删除 JsonDotNet 文件夹。

JsonDotNet 文件夹


小智 2

我在使用 Newtonsoft.Json.dll 添加另一个包后遇到此问题,导致冲突。对我来说,删除其中一个重复项解决了问题。