Search Unity

Do I need nuget packages for things not in net 2.0?

Discussion in 'General Discussion' started by Tomnnn, Sep 1, 2020.

  1. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    I tried to import system.text.json into my project, some googling lead me to discover that the project had defaulted to .net 2 and that I needed at least 3.0. I see Unity now supports .net 4.x, oh boy! But when I changed that project setting, closed everything, then re-opened everything my editor still can't find system.text.json. Is this a weird microsoft versioning thing or a unity thing?

    I see TargetFrameworkVersion = 4.7.1 in the csproj. If I have to install nuget, should I revert to .net 2 for the project settings?

    I'm doing some network stuff with a non c# server and I think I'd rather just c#->json the standard C# way than figure out the unity json utility :)
     
    Nanomid likes this.
  2. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    Tomnnn likes this.
  3. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    The "TotalJSON" unity package I tried earlier today seems to be ok at a glance.

    How do I get my hands on that? I googled around and I'm getting some noise. Are you referring to this project? https://github.com/jilleJr/Newtonsoft.Json-for-Unity Or some newtonsoft namespace I seem to be unable to use or a unity package referenced in some heated discussions I seem to be unable to find?

    --edit: I revisited one of the discussions and found newtonsoft by adding it to the manifest. I'm fine if this is how it has to be added to a project, just wary of editing a manifest directly instead of having some way to do it via unity gui.
     
    Last edited: Sep 1, 2020
  4. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    If you download the latest release from my link, and import the unitypackage into your project, you'll get a menu item at the top of the screen that says "NuGet." The first dropdown option is "Manage NuGet Packages," and clicking it will bring up a window that allows you to import packages. It shows a bunch of packages online. For me the first one is Newtonsoft.
     
  5. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Oh... I found it somewhere else. Is the method I opted for dangerous? :) I found it by adding com.unity.nuget.newtonsoft to the manifest.

    How much worse is that than your suggestion? From your phrasing I thought you were suggesting newtonsoft as an alternative to nuget :p

    I guess getting access to nuget packages would be better than relying on private unity guts, I'll give that a shot next, thanks! Maybe I can find system.text.json in there, when ever I google newtonsoft I primarily get links about migrating away from it to the other.
     
  6. EternalAmbiguity

    EternalAmbiguity

    Joined:
    Dec 27, 2014
    Posts:
    3,144
    It shouldn't matter as long as you have the regular namespace.

    Newtonsoft is perfectly fine. The docs show pretty clearly how to use it.
     
    Tomnnn likes this.
  7. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    Any NuGet packages that has a .NET Standard 2.0 DLL is good to go, especially good for IL2CPP because .NET Standard 2.0 does not have API that requires JIT.

    I have used the latest JSON.NET downloaded from NuGet (with the Standard 2.0 DLL) extensively in multiple projects. You could get by with that "JSON.NET for Unity" but it's based on a very old JSON.NET version and has not been updated since.
     
    Tomnnn likes this.
  8. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Hmm, alright. I did a quick test and the interface for it is fine, simple serialize and deserialize. I'll try the nuget thing anyway just to get access to other potentially useful things.

    Will there be issues with having the player set to 4.x? Or is that solely an IL2CPP issue for a handful of packages because of the AOT vs JIT stuff. Not that I know anything about any of those acronyms, but they all came up while doing research :p
     
  9. Neonlyte

    Neonlyte

    Joined:
    Oct 17, 2013
    Posts:
    516
    Recent Unity version has dropped the older .NET Runtime so 4.x is the only choice.
    And yes, Choosing Standard 2.0 DLL over Framework 4.X DLL in a NuGet package is exactly an IL2CPP side effect due to being an AOT compilation.
     
    Tomnnn likes this.