Why does Unity silently remove my NuGet System.Text.Json Package?

I’ve tried various versions of System.Text.Json and both .Net 2.0 standard and .Net 4.x.
In Visual Studio I can add them in the NuGet package manager and the project will ‘Rebuild’ with no errors.
System.Text.Json exists in my Assembly C-Sharp references just fine.

I go back to Unity and see compilation errors:

Assets\Scripts\JSONTest.cs(4,19): error CS0234: The type or namespace name 'Json' does not exist in the namespace 'System.Text' (are you missing an assembly reference?)

After switching back and forth a few times between Unity and Visual Studio I find the package System.Text.Json has now been removed from my Assembly reference.
No warning, no reason, just removed. I’ve tried 2020.1x and 2019.4x Unity versions, no difference.

You need to create a rsp file and add it to the root of your assets folder. Nuget package manaer in VS does not translate to Unity the way you think it would.

Just use notepad to create the rsp file.

Here is an example of one that I had to use.

If System.Text.Json is not build into .net framework… Then just use nuget to download on a temp VS project. Then copy out the DLL and import into your Unity project.

1 Like