Add Reference is missing in Visual Studio when using with Unity 3D - Need Npgsql.dll

馋奶兔 提交于 2020-01-22 11:08:27

问题


I installed Unity 2017 with Visual Studio 2017. I am attempting to add an external DLL to the Visual Studio project through the solution explorer. When I right click on References, the "Add Reference" option is completely missing!

I'm trying to use NpgSQL. Hence, the need to add npgsql.dll.

Can anyone give light?


回答1:


The Add Reference... is in a different place in this case.


Things to do in Unity:

Create a folder named Plugins as a child to your Assets folder. (Assets\Plugins...)

Next copy your DLL to this plugins folder. You can do this using Windows Explorer or just drag it into the folder in the Unity editor, like shown:


Things to do in Visual Studio:

Click on Analyzers in your project as shown below, then click Project from your menu, then navigate to Add Reference...:

Now Browse to your DLL:

And... there it is:




回答2:


Accepted Brien's answer (Thank you, Brien!).

I'm adding my own answer pertinent to Npgsql.dll, because it's apparently a common problem all over the internet with poor documentation. If you got here from google about Npgsql.dll then read on:

Unity (for some unknown reason) comes bundled with it's own npgsql.dll inside of the application mono/2_0 folder. Some people have reported conflicts with this.

Many of the npgsql.dll versions currently do not work with Unity. Attempting to include them in Unity's assets will cause Unity to throw a Type error. This is what caused me to think that I needed to add the file as a reference in C#. This is why I came here and asked the question about Add Reference. But, with Unity, this was simply wrong on my part.

As far as I can tell, Unity insists on managing all project properties and references for you. Both managed and unmanaged DLLs must be added via Unity assets. Even Visual Studio project properties cannot be changed within Visual Studio for Unity. And if you attempt to edit the .csproj files (for instance to disable compiler warnings), Unity will overwrite the .csproj files completely next time you load your Unity project.

Anyone who has problems getting Npgsql.dll to work in Unity needs to use the proper Unity workflow where you drop npgsql.dll into Unity assets. If you get errors, it's an npgsql.dll version conflict. Try other versions of the dll first.

This gentleman has provided a Unity specific build to resolve a namespace conflict (Just pull the dll from the bin folder on the Github link): Unity NPGSQL.DLL

Unity 2017 currently allows you to change to .NET 4.6 as an experimental setting. Some people have toyed with using that setting to get newer versions of npgsql.dll to work properly, but they report intermittent results. For now, I solved my problem with Unitynpgsql.dll. It's an older build, so hopefully I won't run into any features I need that it doesn't support. If so, I'll probably just work around them.

To anyone else trying to make npgsql.dll work in Unity: do not despair, just try to resolve the version conflicts. Also here is another relevant recent thread about it: Barebones Master Server Npgsql.dll Issue - January 2018



来源:https://stackoverflow.com/questions/48875798/add-reference-is-missing-in-visual-studio-when-using-with-unity-3d-need-npgsql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!