Newtonsoft Json package

I ran into this issue today while upgrading an old project. I wrote up the exact steps I used to resolve the issue, based on this thread, other threads, and the instructions found here: Unity - Manual: Embedded dependencies. I added them to the most popular thread on this topic in the Package Manager forum , but I thought it would also be useful to add them here to the most popular thread on this topic in the Scripting forum as well.

The key is to embed the package and remove all other versions. The embedded version will take precedence for Unity and your other modules, and can be modified to suit your needs.

These steps will need to be taken into account and well documented for users when publishing assets which depend on Json.NET to the Asset Store. The specific Json.NET package requirements should be clear to the consumer.

Steps for embedding the Newtonsoft Json.NET package into your project:

  1. Open the Package Manager window.
  2. Select the ‘+’ menu in the top left corner.
  3. Select “Add package by name…”.
  4. Paste “com.unity.nuget.newtonsoft-json” into the “Name” field.
  5. Select the “Add” button.
  6. Expand the “Packages” directory in the Project window.
  7. Right-click the “Newtonsoft Json” folder, then select “Show in Explorer”. Opening the package this way reveals the actual package that is currently referenced by Unity. Currently, this should be in the “Library/PackageCache/” directory of your project.
  8. Open another file explorer window to the “Packages” directory of your project.
  9. Copy the “com.unity.nuget.newtonsoft-json@[major].[minor].[build]” package folder from the “Library/PackageCache/” directory to the “Packages/” directory.
  10. Remove the “@[major].[minor].[build]” section of the package folder name that is now in the “Packages/” directory.
  11. Ensure the newly embedded package will be added to source control.
  12. All modules that depend on Json.NET should have their own locally embedded versions of Json.NET assemblies removed. For example, at this stage I deleted the “Assets/JsonDotNet/” directory from my project and my issues went away.
  13. You may now customize the package, as long as all dependent modules are compatible with the customized version. If some modules do not agree on an acceptable version, then I think those modules are not compatible.
5 Likes