Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Unity Future .NET Development Status

Discussion in 'Experimental Scripting Previews' started by JoshPeterson, Apr 13, 2021.

  1. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    It does compile now, but it crashes the process in runtime instead. Should I submit a new bug report or email them about the old one?
     
  2. Roc916

    Roc916

    Joined:
    Jun 5, 2021
    Posts:
    2
    Can't use System.Collections.Immutable、Microsoft.Extensions.Logging... librarys(b6 \ b7).
     
    Last edited: Aug 14, 2021
  3. SugoiDev

    SugoiDev

    Joined:
    Mar 27, 2013
    Posts:
    395
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks for the details - some GC workloads are definitely slower in Unity than with .NET 6. Our plan for .NET 6 is to use the CoreCLR GC, so Unity should see much improved performance with these GC workloads. However, we still have some research to do to prove that is feasible to use, so I'm unsure that it will happen.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Depending on the workflow, I would expect that raw C++ will be faster in some cases, because IL2CPP must implement the .NET VM, which places certain requirements on the code. If you are looking for CPU-bound performance with minimum use of the VM features, Burst is definitely the way to go.
    I've replied on the other thread. 1 GB of generated C++ code seems like a lot - I think we can investigate what is
    happening there.

    I don't see anything in this code that should not work. If you do see something like this again, please let me know via the forums or submit a bug report.
     
    JesOb likes this.
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    There are definitely steps that we can take to ease the transition, and we plan to do everything we can to make it as simple as possible to migrate to a .NET 6 world. But even this case is non-trivial. Many users will not know how to make these modifications on their won (nor should they need) to.

    So although this is not strictly a breaking change, this is the kind of thing I'm referring to.
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Please submit a bug report for this issue. It might be the same as the issue @SugoiDev linked to, but we'd still like to have details in case it is different.
     
  8. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Unfortunately no, Unity does not support http/2 yet. The version of Mono that Unity uses does not have support for it. When we get to .NET 6 though, I suspect that it will be supported, since the .NET 6 class libraries and CoreCLR have supported it since .NET Core 3.0, I believe.
     
  9. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    If anybody wonders, I was told to open a new case, number 1357908.
     
    LeonhardP and JoshPeterson like this.
  10. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Has anyone got it working? No idea how to add https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/source-generators-overview
    Code (CSharp):
    1.     <ProjectReference Include="path-to-sourcegenerator-project.csproj"
    2.                       OutputItemType="Analyzer"
    3.                       ReferenceOutputAssembly="false" />
    as csproj files are not used in build process. I've also tried https://docs.unity3d.com/Manual/roslyn-analyzers.html and csc.rsp -a but both didn't generate any code.

    Directory.Build.props work but only for rider/vs not Unity build pipeline.
     
  11. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    I made it work without much effort.
    I used same method as with analyzer:
    - create VS project;
    - build dll;
    - put it into Unity project;
    - mark dll with RoslynAnalyzer label;

    I see one problem with that Microsoft doc. They use Microsoft.CodeAnalysis.CSharp version 3.9.0 but Unity 2021.2 use Roslyn 3.8.0 (at least it was last time I checked). So it will not load such generator becouse it can't load all dependencies. To work with Unity generator should use version 3.8.0
     
    Last edited: Aug 17, 2021
  12. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    What about?
     
    Mindstyler likes this.
  13. Nirlah

    Nirlah

    Joined:
    May 6, 2018
    Posts:
    10
    I also got the source generators to work by building a dll in a different project.
    Also, for a more convenient pipeline, I tried building it with Unity’s AssymblyBuilder and props file; Sadly, only the analyzers work for this solution while building fails when including source generators.
     
    jasonboukheir likes this.
  14. Mindstyler

    Mindstyler

    Joined:
    Aug 29, 2017
    Posts:
    248
    What did you do specifically to make it work?
     
  15. jasonboukheir

    jasonboukheir

    Joined:
    May 3, 2017
    Posts:
    84
  16. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Got it also working.
    All platforms can be disabled, together with analyzer all required dlls have to be added, they can also have platforms and auto-reference disabled. These don't have RoslynAnalyzer label.

    I even had to add System.Memory (net standard project) as somehow System.Collections.Immutable can't use included one.
     
    jasonboukheir likes this.
  17. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    Yep, I disable all platforms. also I disable auto reference and validate references.
    I did not include any additional dll.
    Additional dlls should not be required. Those dlls are part of compiler. Probably you have validate references enabled or something broken in latest Unity beta
     
  18. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    I guess it depends on what generator uses. It didn't work without them.
     
  19. Nirlah

    Nirlah

    Joined:
    May 6, 2018
    Posts:
    10
    Follow https://docs.unity3d.com/2021.2/Documentation/Manual/roslyn-analyzers.html and build the project with the following config:
    Code (CSharp):
    1. <Project Sdk="Microsoft.NET.Sdk">
    2.  
    3.     <PropertyGroup>
    4.         <TargetFramework>netstandard2.0</TargetFramework>
    5.     </PropertyGroup>
    6.  
    7.     <ItemGroup>
    8.       <PackageReference Include="Microsoft.CodeAnalysis.Common" Version="3.8.0" />
    9.     </ItemGroup>
    10.  
    11. </Project>
     
    Last edited: Aug 18, 2021
    VolodymyrBS likes this.
  20. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    Since the .Net Framework setting doesn't really limit to .Net Framework, I'd suggest renaming it to Full or .Net Framework 4.8 + .Net Standard 2.1. Having it not specified in the dropdown leads to confusion like here with people saying that Span being present in it is a bug https://forum.unity.com/threads/2021-2-0b6-and-system-memory-readonlyspan-under-net-4-8.1152104
     
    bdovaz likes this.
  21. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks for the suggestion. We've gone back and forth with a number of options about how to present this in the GUI. I'm not sure that we have settled on the final one yet, either. I'll investigate the linked bug report - indeed, changing the name of this option might help avoid confusion.
     
    Tanner555 likes this.
  22. TieSKey

    TieSKey

    Joined:
    Apr 14, 2011
    Posts:
    226
    Sorry to quote you for something offtopic but, is there any chance you could "communicate" to the relevant management levels in Unity how happy we have been with your "style" of customer/community management? (I'm not expecting a concrete answer from you, just a "I'll see what I can do" is more than enough, thx).

    Unfortunately other teams over on Unity have terrible communication skills/policies ranging from complete silence to bait-and-switch post and threads. Since from time to time Unity offers some "prices" for reporting bugs, participating in betas and/or interviews, I guess there is some level of interest from upper management in getting useful feedback.
    But since feedback is a 2-way road, it seems a bit contradictory to have a "bug report contest with rewards" in one part of the forum and complete lack of unity staff interaction for half a year or more on others.

    For anyone else reading this, "like" this post if u agree but try to refrain from actually posting as to limit the number of offtopic messages. I know I'm being selfish, but didn't want to pm Josh just for this.
     
    Trigve, OregonGhost, nitz and 39 others like this.
  23. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I'm happy to hear that the communication in this thread has been useful for many of you! It certainly have been useful for us on the teams working on this effort.

    More generally, I can say that feedback is very important internally at Unity. I suspect on some teams that does not translate externally to the forums as well as we would like. In fact, this thread was a bit of a step outside the box for your team. Since the results have been positive, we will do our best to work with other teams to communicate in similar ways.

    Of course in a large organization "I'll see what I can do" is the best I can offer, but I'm optimistic.

    In the meantime, let's keep the conversation here going, the feedback on this thread has been wonderful. Thanks!
     
    stonstad, nra, Wattosan and 16 others like this.
  24. KamilCSPS

    KamilCSPS

    Joined:
    May 21, 2020
    Posts:
    448
    The "Unity Success Team" & their "Success Advisors" have direct contact with Unity devs and report to higher-up as Unity uses them to take the 'pulse' of paying customers. Kinda as if 'marketing' were to tell direction that Dev-Team X/Y/Z is doing a good job.

    Sending any, all, every type of feedback to them tends to reverbate up in the chain to other team-leads and managers from what I've seen. We have regular, scheduled meetings with them twice a year but can contact them anytime for anything - strongly encourage everyone to do the same in relation of Josh's team and the great job they're doing!
     
  25. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    Using a .Net Standard 2.1 dll that references System.Runtime.CompilerServices.Unsafe via Nuget gives a MissingMethodException when any API from that is called. The editor should instead refuse to load such dll. Reported, case 1360423.
     
  26. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks for the bug report, we will investigate this!
     
  27. Digika

    Digika

    Joined:
    Jan 7, 2018
    Posts:
    225
    This is how UnrealCLR
    https://github.com/nxrighthere/UnrealCLR
    solved this:
    https://github.com/natemcmaster/DotNetCorePlugins
    for Net .5

    Just FYI
     
    JoshPeterson likes this.
  28. R1PFake

    R1PFake

    Joined:
    Aug 7, 2015
    Posts:
    542
    Some questions about the state of .NET 6 support:

    - Will the Unity support/update for .NET 6 be near the official release window of .NET 6 it self or later?
    - Which Unity versions will support it?
    - Which C# version will be supported? I hope the newest, which should be C# 10 once it is released?
    - Will future C# / .NET updates be easier / faster after Unity supports .NET 6?

    One additional question, I hope this is not off topic, but will Unity support the new official C# source generator feature, I think it is also planned to be released with .NET 6? (Currently still in preview)
     
    CaseyHofland and bdovaz like this.
  29. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
    Latest Unity 2021.2 beta already support it :)
     
  30. Lhawika

    Lhawika

    Joined:
    May 27, 2015
    Posts:
    53
    @Jes28 Hi, would you happen to have resources on how to get started with those ?
     
  31. JesOb

    JesOb

    Joined:
    Sep 3, 2012
    Posts:
    1,109
  32. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I'm not sure about timelines yet, but with the .NET 6 release for Microsoft scheduled for release in November, I think that Unity's support will be later than that.

    I'm not sure about this either, it is too early for us to tell. I know that it won't be 2021.2, and likely not 2022.1, but we'll see.

    Our goal will be to support the latest C# version at the time we release .NET 6 support, so at least C# 9, and maybe C# 10.

    Sorry, I just don't know enough yet to give many firm answers here, but I'll update this thread when I do know.
     
  33. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    @JoshPeterson what about csproj files support? I read some time ago that you were working or at least evaluating replacing asmdef files with csproj files.

    This would provide native nuget support, native analyzers support, native source generators support, referencing non unity code .net projects without compiling them before, ...
     
  34. PetrisPeper

    PetrisPeper

    Joined:
    Nov 10, 2017
    Posts:
    66
    jasonboukheir likes this.
  35. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  36. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    418
    There is a long term plan to support such a scenario, but we haven't planned for it yet (mostly because the team that could work on it is a bit overwhelmed these days by other higher priority issues)
     
    Nexer8, NotaNaN, Tanner555 and 4 others like this.
  37. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    @JoshPeterson I'm running into major problems using my organization's internal packages since .NET Standard 2.1 support has been added in 2021.1b6.

    Until now I was using NuGet packages extensively via @xoofx's fantastic solution to which I have contributed several PRs: https://github.com/xoofx/UnityNuGet

    In that repository if you don't know it converts NuGet packages to UPM format and adds the define NET_STANDARD_2_0 in each *.meta of each *.dll. This makes it very convenient to add NuGet dependencies in the UPM world.

    But now I encounter several problems.

    1. It is not possible to choose between .NET Standard 2.0 or .NET Standard 2.1.

    With the following package for example it doesn't work because it only targets 2.0 and it brings the dependency "Microsoft.Bcl.AsyncInterfaces" which is not necessary in 2.1 but it should still compile in Unity because in a native .NET Core console project I can import it without any problem because it fallbacks to 2.0 target:

    https://www.nuget.org/packages/AWSSDK.Core/

    In this case it is a breaking change, since I will not be able to update any Unity project that uses @xoofx's UPM scoped registry.

    2. NET_STANDARD_2_0 is defined instead of NET_STANDARD_2_1.

    This is incorrect since we are in .NET Standard 2.1 and leads to confusion. If you have a Unity package with code that only compiles to 2.1 you cannot differentiate it from 2.0.

    It is also confusing that in Player Settings it says ".NET Standard" without version number.
     
    goncalo-vasconcelos and SugoiDev like this.
  38. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    As you may have read in my previous post, NuGet support is something I've been pursuing and asking for on the forum for years but it never seems to be a priority for Unity.... Thanks to your solution I have been able to fix it until this b6 which has added support for 2.1 and broke everything.

    Supporting *.csproj files would solve a lot of problems at once.
     
    Huszky likes this.
  39. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Can you elaborate on this? I'm unclear what the problem is. Is there a specific C# compiler error?

    Good point. I think this was discussed previously, and we did some internal discussion. I can add a NET_STANDARD_2_1 define when Unity compiles C# code that will always be defined with versions of Unity from 2021.2 and later. We have added a new define NET_STANDARD which serves this purpose now.

    So at the moment, both of NET_STANDARD_2_0 and NET_STANDARD are defined. I'll add NET_STANDARD_2_1 as well though, as that will be less confusing.

    This was intentional, because we don't plan to support .NET Standard 2.0 and .NET Standard 2.1 as separate Api Compatibility Levels. Since we only support .NET Standard 2.1, we dropped the version number.
     
    SugoiDev likes this.
  40. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    If you open the attached project on 2020LTS it works but if you open in 2021b it doesn't compile with the following error:

    upload_2021-9-1_20-30-55.png
     

    Attached Files:

  41. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Can you send the full text of the error message (not a screen shot - it looks like the text is cut off there).
     
  42. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    upload_2021-9-1_20-37-11.png

    Assets\NewBehaviourScript.cs(9,9): error CS0433: The type 'IAsyncEnumerable<T>' exists in both 'Microsoft.Bcl.AsyncInterfaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' and 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
     
  43. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Thanks for the details. We'll investigate this a bit and I'll let you know.
     
    bdovaz likes this.
  44. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    With the project I have attached in my previous message you can easily reproduce it by opening it in 2020LTS and then in 2021b where the compilation error will appear.
     
    JoshPeterson likes this.
  45. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  46. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    I can't without getting rid off @xoofx's UnityNuget automated setup and falling back to get all my NuGet dependency chain manually (+100 assemblies) downloading them one by one or checking one by one for this duplicities.

    I know that if I pull all that dlls manually it works but what I'm saying is that .NET Standard it's backwards compatible on traditional .NET Core project, I don't understand why it isn't on a Unity project.

    It's a serious breaking change for all people who are using .NET Standard 2.0 assemblies, it will break in cases like this. It's a very big problem because on 2021b it automatically updates to 2.1 without asking and it's not possible to go back to 2.0.
     
  47. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yeah, this is what we are trying to determine. Is this some issue with UnityNuGet? Or is this some problem with the reference profile that Unity is using.

    I agree though, we need to address it.
     
  48. bdovaz

    bdovaz

    Joined:
    Dec 10, 2011
    Posts:
    1,053
    The problem is with the reference profile that Unity is using.

    Here you have another NuGet package that would break (a package with millions of downloads):

    https://www.nuget.org/packages/System.Text.Json

    If you see it only targets .NET Standard 2.0 (no 2.1) and it depends on:

    Microsoft.Bcl.AsyncInterfaces (>= 5.0.0)
    System.Threading.Tasks.Extensions (>= 4.5.4)

    Both dependencies are included with .NET Standard 2.1.

    As I said on a traditional .NET Core project it works but on a Unity project it shows that duplicity error.

    Another example:

    https://www.nuget.org/packages/Microsoft.Extensions.Hosting.Abstractions/3.1.8

    Only targets .NET Standard 2.0 (no 2.1) and it depends on:

    Microsoft.Bcl.AsyncInterfaces (>= 1.1.1)

    And also on this case I can't use the 5.x version of Microsoft.Extensions.* packages because of this issue I reported some time ago (only fixed on 2022alphas+): https://github.com/dotnet/runtime/issues/52990
     
    Last edited: Sep 1, 2021
    Huszky likes this.
  49. VolodymyrBS

    VolodymyrBS

    Joined:
    May 15, 2019
    Posts:
    150
    It doesn't work so smooth with Unity becouse how Nuget dependencies resolve. Target runtime is selected for each package separately.

    For example we have 3 packages:
    • A - has netstatdard 2.0 and net 5.0
    • B - depend on A and has netstatdard 2.0 and netstatdard 2.1
    • C - depend on B and has netstandard 2.0 only.
    We add package C to our program that target netstandard 2.1. Than our app will have C with netstatdard 2.0, B with netstatdard 2.1 and A with net standard 2.0.

    So to simulate similar with unity we need to have multiple dlls for different targets with Define Constraints that will select dll depending on target runtime
     
  50. Kamyker

    Kamyker

    Joined:
    May 14, 2013
    Posts:
    1,091
    Doesn't that mean that UnityNuget has to be updated?
     
    jasonboukheir likes this.