Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 205
JamesHoux Avatar asked Feb 19 '18 23:02

JamesHoux


People also ask

How do you add a reference in unity?

To add a reference, click the + icon under the References section and choose your file. Unity uses the references to compile the assemblies and also defines the dependencies between the assemblies. To mark the assembly for testing, enable Test Assemblies in the Inspector. This adds references to unit.

How do I add a missing reference in Visual Studio?

If you're using Visual Basic, select the References page, and then click the Reference Paths button. In the Reference Paths dialog box, type the path of the folder that contains the item you want to reference in the Folder field, and then click the Add Folder button.


2 Answers

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:

enter image description here


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...:

enter image description here

Now Browse to your DLL:

enter image description here

And... there it is:

enter image description here

like image 141
Brien Foss Avatar answered Sep 25 '22 15:09

Brien Foss


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

like image 37
JamesHoux Avatar answered Sep 25 '22 15:09

JamesHoux