【发布时间】:2021-06-27 10:15:03
【问题描述】:
我有一些我在 Unity 2019.4 中通常使用的脚本,并且还编译成单独的 DLL 以在没有源代码的情况下分发。一切正常,直到我开始在几个地方使用 System.Array.Empty<T>(),这在 Unity 中运行良好,但阻止我编译单独的 DLL。
- 最初,我将 Target Framework 设置为
Unity 3.5 .net full Base Class Libraries,但现在出现错误:'Array' does not contain a definition for 'Empty' - 显然
Array.Empty是在.NET Framework 4.6中添加的,但如果我将目标框架设置为那个(或更高版本),我会得到:The type 'ISet<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'从我使用HashSet<T>的任何地方(即使我没有使用@ 987654328@直接)。 - 如果我从 Unity 安装目录手动添加对
System.dll的引用,它会给出完全相同的错误,但会显示ISet<>现在在netstandarddll 中。 - 从 Unity 安装目录中添加对
netstandard.dll的引用会得到Predefined type 'System.Object' is not defined or imported。 - 尝试通过引用
mscorlib.dll来解决这个问题,得到The type 'HashSet<T>' exists in both 'System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' and 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
那么我应该使用什么目标框架和参考来为 Unity 2019.4 编译 DLL?
【问题讨论】: