NuGet packages in Unity

2020-03-19 06:30发布

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?

4条回答
闹够了就滚
2楼-- · 2020-03-19 06:55

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.

查看更多
forever°为你锁心
3楼-- · 2020-03-19 06:57

You have to set up the downloaded nuget /is in packages folder/ plugins manually. Nuget doesn't know which plugin can use unity and how. You can set their parameters in inspector: editor, standalone ... x86,x64 ...

查看更多
爷、活的狠高调
4楼-- · 2020-03-19 07:06

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

查看更多
虎瘦雄心在
5楼-- · 2020-03-19 07:13

There is NuGet2Unity that allows to convert any Nuget package to a '.unitypackage'. I've used it to convert "SpecFlow" and i was able to import the resulting Unity Package. Check out their Examples.

It worked for me with:

dotnet.exe run -n specflow --version 3.0.225

Note that you might need to skip dependecies that are deliverd by the NugetPackage which are already deliverd by unity itself.

查看更多
登录 后发表回答