简体   繁体   中英

Unity not finding DLL dependency of another DLL (both in Assets folder)

Background info (might be relevant):

  • Using Unity 2017.2 with "Scripting Runtime Version" set to "Experimental (.NET 4.6 equivalent)"
  • Writing code in Visual Studio 2017 (not MonoDevelop)

I have a Unity project that makes direct use of a third-party DLL ("library A"), which I've added to the project's Assets folder. Library A depends on another DLL, "library B", which I've also added to the Assets folder. Library B is not used by any scripts in the Unity project. Both libraries A and B are written in C# and target .NET 4, ie, they're both managed code.

Once added to the Assets folder, both libraries A and B are listed under "References" when the project is opened in Visual Studio and "Copy Local" is set to "True" for both (although I don't know if Unity uses that property).

However, when running the project in the Unity editor, various calls to library A raise exceptions that indicate that library B isn't available. The only way I've been able to get it to work is by placing a copy of library B in C:\\Program Files\\Unity\\Editor (the directory containing Unity.exe, the Unity editor executable).

I've used libraries A and B in other, non-Unity projects and never had any issues (Visual Studio copies them both to the output directory as long as they're referenced). Am I missing a Unity-specific step that's necessary to tell it that library B is required?

I just wanted to share how i get this done. I'm using Unity 2019.2.10f1 by the way.

I have many of my own and third party managed dll files in my project, and I copy them all to ProjectFolder\\Assets\\Resources\\

and I've never had any problem calling out to any of the libraries, or those libs calling each other.

Maybe the issue is that since your second library (library B) is not referenced by any scripts, Unity is not bundling it and making it available at debug/runtime.

In my experience, I have found that if you want something to be retained in your build, (any unreferenced assets that may be consumed dynamically at runtime), stick it in the Resources subfolder of Assets.

A second option may be to construct some dummy call to the second 'Library B' (that does nothing, perhaps construct and dump), so that Unity thinks that it is needed and includes it in your build.

Not sure if that helps, but Good Luck!

Unity actually has a special folder called "Plugins" directly under the Assets folder that you can use. This will allow you to add references to dlls made outside of Unity and link against them. You can even have them sorted by targets!

  • Assets/Plugins/x86
  • Assets/Plugins/Android
  • ...

The plugins accepted are all these following extensions: .dll, .winmd, .so, .jar, .aar, .xex, .def, .suprx, .prx, .sprx, .rpl, .cpp, .cc, .c, .h, .jslib, .jspre, .bc, .a, .m, .mm, .swift, .xib, .dylib, .framework, .bundle, .plugin

Unity 2020.3 Plugins Documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM