Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet packages in Unity

Tags:

I want to use some NuGet packages inside Unity. I achieved that Unity finds the downloaded DLLs according to this article (https://www.what-could-possibly-go-wrong.com/unity-and-nuget/). The nuget.config file can be configured to download the packages into the Plugins folder inside the Assets folder. The Problem is that NuGet downloads multiple versions of each DLL (eg net46, netcore50, netstandard21, so forth) and Unity doesn't like multiple DLLs with the same name. I know I could simply put the DLL inside the Plugins folder by hand, but unfortunately that is not a solution which would please me.

Do you have any idea how I could work around this problem? Is it possible to configure NuGet to just download one DLL for each dependency?

like image 458
krumbi Avatar asked Nov 23 '18 13:11

krumbi


People also ask

Where is the unity package manager?

Accessing the Package Manager window. To open the Package Manager window, navigate to Unity's main menu and go to Window > Package Manager.

Can NuGet packages be used in unity?

NuGet is the package manager for . NET. NuGet is integrated into Visual Studio. However, Unity projects require a special process to add NuGet packages because when you open a project in Unity, its Visual Studio project files are regenerated, undoing necessary configurations.


3 Answers

Just thought I'd add this in case it helps anyone

I used the Nuget for Unity asset (free) to import a package (websocketsharp) and it was really easy and painless. The references in VS worked immediately as well

The package you're trying to import naturally has to be compatible with Unity but that's the same even if you import it manually. So I'd recommend giving this a try

like image 148
FearlessHyena Avatar answered Sep 19 '22 14:09

FearlessHyena


Here are the details,

1. go to your desired NuGet package webpage.
2. on the right side **Download Package** option click it.
3. your package **.nupkg** file will be downloaded.
4. change its extension to .zip and extract it
5. go to lib and copy your package dll file from net or any netstandard folder. For [your unity project compatibility purposes][2] view this:

enter image description here

    6. open unity workspace and create plugin folder 
    7. paste your dll file here.

Here is the video guide, i have imported newtonsoft.json pacakge in unity

like image 28
Muhammad Faizan Khan Avatar answered Sep 19 '22 14:09

Muhammad Faizan Khan


You really don't wanna go down the path of configuring Unity to work with Nuget automatically. That article is rather old. With Unity 2018, you get a .net standard 2.0 compatibility level, which should be perfect for Nuget packages. Simply download the package using a separate VS project (as mentioned in the article), then take the netstandard20 version of the DLL and place it in your Unity project.

like image 18
Arshia001 Avatar answered Sep 22 '22 14:09

Arshia001