Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 [email protected] 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?

like image 429
Question3r Avatar asked Sep 01 '19 14:09

Question3r


People also ask

How do I add a NuGet package to VS Code?

To find and install a NuGet package with Visual Studio, follow these steps: Load a project in Solution Explorer, and then select Project > Manage NuGet Packages. The NuGet Package Manager window opens. Select the Browse tab to display packages by popularity from the currently selected source (see Package sources).

How do I add a Unity package to Visual Studio?

Install Visual Studio and UnitySelect Install, or Modify if Visual Studio is already installed. Select the Workloads tab, then select the Game development with Unity workload. If Unity isn't already installed, select Unity Hub under Optional. Select Modify or Install to complete the installation.


1 Answers

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.

like image 71
Kroltan Avatar answered Sep 18 '22 00:09

Kroltan