Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Net Standard 2.0/2.1 vs .NET 4.x - what is newer/better?

Discussion in 'General Discussion' started by april_4_short, Aug 19, 2021.

  1. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    At a superficial level (my limited understanding) Net Standard 2.0/2.1 should be something older than .NET 4.x, but it seems these are two different things, and I have no idea what's newer/better, or why/what.

    Can someone speak to me as though I'm a complete imbecile and know nothing about the .NET, Net Standard etc world.. cause that's where I'm at.

    Sorry to clog forums with this. My searches on google only led to more confusions.
     
    marcin-huuuge and viridisamor like this.
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
  3. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    Sorry, read it and many other pages.

    Still can't grok what's the difference between Standard (which seems to be in the 2's) and Framework (which seems to be in the 4's)?

    And why do I choose between these two in Unity?
     
    RiverExplorer likes this.
  4. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,907
    Everything you need to know about these in context of Unity is here. Everything else is good to know but is not crucial.
     
    _slash_, MarkusU and april_4_short like this.
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
    .NET Framework was started back in early 2000s, and went from many, many revisions. The latest version in .NET Framework 4.8.

    At the same time, there were other forms of .NET that emerged, like .NET Core, .NET Native, Xamarin products, etc. It was wild west for a little while. Then Microsoft decided to create a thing called ".NET Standard", which defines a .NET API surface, which different implementations can implement. The important piece is that .NET Standard isn't a specific runtime, it's just a list of APIs that a runtime has to implement to be called .NET Standard compatible..NET Framework API surface is bigger than .NET Standard, but they don't have perfect overlap.

    Now, when it comes to Unity, the API Compatibility level setting specific which API surface you want to target. We allow two choices: .NET Standard and .NET Framework. Generally, .NET Standard has better cross platform compatibility as many non-common APIs in .NET Framework aren't implemented on non-desktop platforms, but it has less .NET APIs available. .NET Framework remains an option if you want to use APIs that aren't available on .NET Standard on platforms that do implement them.

    Generally, I would suggest using .NET Standard and only change to .NET Framework if you absolutely need to.
     
  6. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    I am so very glad I asked. And incredibly grateful you've taken the time to clear this up.

    THANK YOU!!!

    A good long while back, I read somewhere about .NET 4.x in Unity giving better performance, and went "up" to that.

    There was a bit of a speed boost in Play Mode, but there's always been these foibles in builds that I couldn't track down, because I never thought it would be .NET 4.x as I'd wrongly presumed this was the better, newer, all singing, all dancing, ONE, and that I'd have to fix all those foibles in builds later on.

    It never once occurred to me that I should roll back to Net Standard 2.0

    Then, just today, I noticed that the great Keijiro has been using Net Standard 2.0 and 2.1 for his more recent experiments. Knowing he's cutting edge, I found this odd. So thought I'd best find out what is what in this crazy world of .dots and Nets and NETS and Frameworks and Standards and 2's and 4's.

    I hope there's not too many others like me that have naively pushed up to .NET Framework 4.0 etc.

    Cheers!
     
    viridisamor and Krajca like this.
  7. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    That seems to be talking about folks making libraries for multiple platforms, not games.

    Is there are reason they're saying Libraries, and not games?

    eg. do games made with Unity tend to "just work" on many platforms regardless of these choices, whilst Libraries might be doing more exotic stuff?
     
  8. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,907
    Where?
     
  9. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    "...libraries which aim for cross-platform compatibility should target the .NET Standard 2.0 profile."
     
  10. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,907
    Before that section:
    Oh and BTW, it's all about using Unity. There is very little difference if you're writing a library (managed or source code) versus making a game.
     
    april_4_short likes this.
  11. april_4_short

    april_4_short

    Joined:
    Jul 19, 2021
    Posts:
    489
    Do you think it might be a typo, that they meant to write game, but were so busy talking about libraries of APIs that the word was on their brain for too long?
     
  12. kaneWadel32

    kaneWadel32

    Joined:
    Sep 6, 2017
    Posts:
    9
    Thanks for the answer; So what are we suppose to take when we want to integrate FIREBASE package (dotnet4) ?
     
  13. AlexFCL

    AlexFCL

    Joined:
    Mar 27, 2013
    Posts:
    17
    Just to chime in on my findings on this discussion. From the site (https://dotnet.microsoft.com/platform/dotnet-standard) ".NET and .NET Core" was mentioned and I was confused whats the difference between .NET and .NET Core turns out MS renamed .NET Core to .NET when they updated from .NET (Core) 3.1 to .NET 5. They skipped the numbering "4" to avoid confusion with the .NET Framework numbering (.NET Framework version uses 4.x). So basically .NET Core and .NET they refer to the same thing (now).

    Sauce: https://docs.microsoft.com/en-us/dotnet/core/whats-new/dotnet-5
     
    Last edited: Apr 12, 2022
  14. newguy123

    newguy123

    Joined:
    Aug 22, 2018
    Posts:
    1,234
    Can somebody lend a hand please.

    I'm using Unity for offline rendering via Unity recorder only.

    I'm installing an asset from asset store and part of the requirement is to set player > Api Compatibility Level to .Net 4.x

    Now I'm on Unity 2022.2.0a10 and there are only 2 options:
    .NET Standard 2.1
    .NET Framework

    ....no .Net 4.x

    How do I get .NET 4.x to show in the list?
     
    jeroll3d likes this.
  15. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
    .NET Framework is .Net 4.x.
     
    Thanitsak, Meatloaf4 and newguy123 like this.
  16. rainboww

    rainboww

    Joined:
    Jan 5, 2017
    Posts:
    125
    Is there a difference in performance between .NET 2 and .NET 4?
     
  17. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,504
    There shouldn't. Individual APIs might have different perf characteristics in rare cases, but overall game performance differences won't be observable.
     
    DevDunk likes this.
  18. AlfieBooth

    AlfieBooth

    Joined:
    Dec 2, 2013
    Posts:
    31
    This is a truly excellent response. Thank you so very much.
     
  19. Max-om

    Max-om

    Joined:
    Aug 9, 2017
    Posts:
    486
    I would say CLR and more importantly JIT compiler is of most importance.

    And it's here we will see the biggest improvemt when we finaly move from Mono CLR to Core CLR