c# - Unity: Visual Studio loses DLL reference after Unity compiles code
问题描述
I am using the System.Compression.ZipFile.dll in a Unity project, and have added the reference to both the the Visual Studio project and within the Unity Editor, and the code compiles and runs as expected without issue.
However, whenever Unity compiles the code, the DLL reference is removed from the Visual Studio Project.
As a result, compiling within Visual Studio afterwords will have namespace errors. These errors are only in in Visual Studio, as the Unity editor does have the reference when it actually compiles the code.
These errors are fixed by re-adding the DLL reference to the solution. I would like to stop the errors from showing up in Visual Studio, as they are rather annoying.
How do I prevent the reference from being removed from the Visual Studio Project when Unity actually compiles the code?
If it helps I am using Visual Studio Community 2015, and the Unity Editor 2018.2.14f1, on Windows 8.1, with .NET version 4.7.1
EDIT:
My mcs.rsp file contains: -r:System.IO.Compression.FileSystem.dll based on a unity forum thread. This is interesting as it is not the expected DLL, and yet it still works.
Adding -r:System.IO.Compression.ZipFile.dll will cause: error CS0006: Metadata file `System.IO.Compression.ZipFile.dll' could not be found.
The relevant errors are:
CS1069 The type name 'ZipFile' could not be found in the namespace 'System.IO.Compression'. This type has been forwarded to assembly 'System.IO.Compression.FileSystem, Version=4.0.0.0, Culture=neutral, Consider adding a reference to that assembly.
Error CS0006 Metadata file ProjectFolder\Temp\bin\Debug\Assembly-CSharp.dll' could not be found
Unity is correctly configured to use .NET 4.x
解决方案
当您使用 C# 7 或 C# 8 中的一些新功能时,会发生此问题。在我的例子中,我正在处理一个基于 .NET 框架 4.6 的旧项目,并将一些 using 块切换为简化的 using 语句。例如,而不是
using (var resource = new ExpensiveStuff())
{
//whatever
}
我做了:
using var resource = new ExpensiveStuff();
//whatever
编译器默默地允许我这样做,但下一次构建失败,CS0006。我花了一个小时才弄明白。我正要重新安装我的 Windows ......哈哈
推荐阅读
- java - 如何通过java中的另一个列表对列表对象进行排序
- xml - 如何避免文件末尾的新行 - xml to csv through xslt
- android - "detail":"JSON 解析错误 - 期望值:第 1 行第 1 列 (char 0) 颤振补丁请求
- mysql - AWS EBS django 无法部署并出现迁移错误
- c++ - 为什么如果我插入 1,2,2 作为输入,结果将是 0 而不是 1
- c# - Unity地形对撞机间歇性丢失碰撞
- sql - 将 ID 重新颁发给具有重复项的记录
- sql - SQL中属于两个不同列的两个不同行的数据之间的差异
- vba - 我在向 Google 日历中添加新活动时遇到问题
- reactjs - saga api调用成功后如何重定向