c# - 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 等)
我该如何解决这个冲突?
解决方案
在我的情况下,从 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\PackageCache
并YouProjectFolder\Library\ScriptAssemblies
重新启动 Unity。
推荐阅读
- javascript - JavaScript 从数组对象中获取数据并放入 html 表中
- sql - 使用联接创建多个表时如何避免“模棱两可”的错误消息
- c# - 如何访问 ASP.Net Core2 cshtml 文件中的数据库(查看)
- nginx - nginx服务无法运行
- java - 如何正确使用 Scatter-Gather 模式?
- python - Seaborn 配对图显示平均线
- python - 从 yaml 文件加载的 python 对象中读取值
- vue.js - .env VUE_APP_ 变量 json?
- date - GNU日期输出特定时间
- java - 替换除 application.properties 之外的 Spring 属性文件中的环境变量