简体   繁体   中英

Install a Nuget package in Visual Studio Code for Unity

I want to save my level files to .json files in the Unity assets folder. Due to the limited features of JsonUtility I want to use Json.NET . I use Linux so I can't access Visual Studio and use Visual Studio Code instead. I wanted to add the package to my Unity project and took the guide from here

Install a Nuget package in Visual Studio Code

First I used this command in the terminal

dotnet add package Newtonsoft.Json

but I got this error

error: Error while adding package 'Newtonsoft.Json' to project '/.../myUnityProject/Assembly-CSharp.csproj'. The project does not support adding package references through the add package command.

After that I installed the Nuget extension and installed Newtonsoft.Json@12.0.2 to my project. I was prompted to run dotnet restore to be able to use the package.

After doing so I got this error

MSBUILD : error MSB1011: Specify which project or solution file to use because this folder contains more than one project or solution file.

So what is the correct way to install third party tools using Visual Studio Code with Unity?

Unfortunately, due to Unity3D's heavy-handed manipulation of SLN files, it is not possible to use NuGet packages within a Unity project.

In the case of Newtonsoft.Json, it is available on the Asset Store for free, you can install from there.


Other packages can be used manually by downloading the .nupkg file from the NuGet website, extracting the DLLs for .NET 4.x, and placing them in your project's Assets folder.

If the library contains native code, you might not be able to use it on every platform, however. But if you get per-platform DLLs, you can set them up in the Unity editor to only be used for the correct platforms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM