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

18,155

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

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

Solution 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

Share:
18,155

Related videos on Youtube

JamesHoux
Author by

JamesHoux

Software engineer, energy researcher, graphic designer, carpenter, metalworker, etc etc.

Updated on June 25, 2022

Comments

  • JamesHoux
    JamesHoux almost 2 years

    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?

  • Brien Foss
    Brien Foss about 6 years
    Thanks for the additional information and explanation. I am sure this will help future visitors with the same problem.