Search Unity

Suggestion: Choose Microsoft.NETCore.UniversalWindowsPlatform version when building

Discussion in 'Windows' started by holo-krzysztof, May 8, 2017.

  1. holo-krzysztof

    holo-krzysztof

    Joined:
    Apr 5, 2017
    Posts:
    77
    (or update it to a newer default version).

    The problem in my case is, that I wanted to use TcpClient, which was not in the first release.
    However, as the solutions are auto-generated on build, each developer has to manually change this in every project because (as far as I know) there is no way to tell Unity which version I need. I'm building on SDK version 14393 if that changes anything. Unity version is 5.5.3 and I won't be able to use a newer one, due to 3rd party dependencies not working with 5.6.

    Is there a workaround for this or do I really need to patch this every time I check it out from source control?

    Edit: Also, I can't even build with an external dll that uses TcpClient because ReferenceRewriter fails.
    The same happens without the dll with just a single code file.

    I have reported this as a bug.

    Also, I have found a workaround (not tested at runtime yet, but it compiles now at least). Note that this modifies files in your Unity installation, so make sure to back them up.
    In my case, I need "Microsoft.NETCore.UniversalWindowsPlatform" 5.2.3 instead of 5.0.0. Here's the required steps:

    • Update Unity's nuget (C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Tools) to a newer version, as it is required to handle this package. Open PowerShell as admin, navigate to the directory where nuget.exe is located and type "nuget.exe update -self"
    • Open C:\Program Files\Unity 5.5.3\Editor\Data\PlaybackEngines\MetroSupport\Tools\project.json and change Microsoft.NETCore.UniversalWindowsPlatform to the required version
    • Open C:\Program Files\Unity\Editor\Data\PlaybackEngines\MetroSupport\Templates\UAP\CSharp\project.json and change Microsoft.NETCore.UniversalWindowsPlatform to the required version
    • Your project should now compile
     
    Last edited: May 8, 2017
  2. bebenzig

    bebenzig

    Joined:
    Jun 25, 2018
    Posts:
    9
    I would totally support that request! It's pretty annoying to only have v5.0.0 per default...
    Also the newest version is already 6.1.7.
     
    Last edited: Sep 4, 2018
  3. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    We're deprecating .NET scripting backend and thus we're not planning to add any new features to it. If you need newer .NET API, I suggest using IL2CPP scripting backend.
     
  4. RyanTremblay

    RyanTremblay

    Joined:
    Aug 31, 2018
    Posts:
    7
    Can you explain how these two things relate? Even if you are using IL2CPP, the code needs to compile against some .NET API contract. Usually for UWP .NET development, this is provided by the version of .NET Core for UWP (the Microsoft.NETCore.UniversalWindowsPlatform NuGet package). If that package is not in the picture when using IL2CPP, then what is the .NET API surface area being compiled against?
     
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    When you're using IL2CPP, there are 4 API targets to compile against, which is the same as all other platforms Unity supports: .NET 2.0, .NET 2.0 subset, .NET 4.6 and .NET Standard 2.0. This is controlled by API compatibility level setting in the player settings.
     
  6. RyanTremblay

    RyanTremblay

    Joined:
    Aug 31, 2018
    Posts:
    7
    So when using IL2CPP, you are actually using a different .NET API surface area than normal UWP development? What if you have an assembly that has already been compiled against Microsoft.NETCore.UniversalWindowsPlatform and uses some API that is not part of .NET 4.6 or .NET Standard 2.0, and then bring that into your Unity project and try to compile with IL2CPP? Does it just blow up?
     
  7. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Microsoft.NETCore.UniversalWindowsPlatform is mostly a subset of .NET Standard 2.0 and .NET 4.6, so it should work.
     
  8. RyanTremblay

    RyanTremblay

    Joined:
    Aug 31, 2018
    Posts:
    7
    Thanks for the extra info. Several comments and questions:
    1. There are thousands of API differences between Microsoft.NETCore.UniversalWindowsPlatform and .NET Standard 2.0/.NET Framework 4.6. Given this, it doesn't seem like it would be that hard to get in a situation where you are calling into one of these APIs.
    2. An obvious example of this would be the various extension methods that make it easier to call into Windows Runtime APIs. For example, System.WindowsRuntimeSystemExtensions.AsTask or System.IO.WindowsRuntimeStorageExtensions.OpenStreamForWriteAsync.
    3. What is the right way to author an assembly that uses Windows Runtime APIs and is ingested as an assembly by Unity when using IL2CPP? Do I still set it up as a UWP class library (which brings in Microsoft.NETCore.UniversalWindowsPlatform) and just be careful not to call any .NET APIs that are not part of .NET Standard 2.0 or .NET Framework 4.6 (including helper methods for Windows Runtime APIs)? Or would I set up a .NET Standard 2.0 or .NET Framework 4.6 project and try to add references to .winmds? Or something else? Is this documented somewhere? The only thing I could find is https://docs.unity3d.com/Manual/IL2CPP-WindowsRuntimeSupport.html, but this is talking about source that is compiled by Unity, not pre-compiled assemblies ingested by Unity.
    It'd be great if you could help clear this up. I'm not sure how to move to IL2CPP with any confidence without understanding how this is supposed to work.
     
  9. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Examples of things you're missing would be nice. Last time I looked, they missing types were not very important.

    These are available on IL2CPP with both .NET Standard 2.0 and .NET 4.6 API compatibility levels.

    Both should work, but as I mentioned, we haven't yet seen issues where people use unavailable APIs. If you run into any that you think should be supported on IL2CPP, let us know. .NET 2.0 class library might be easier to manage if you want to use APIs that aren't available in Microsoft.NETCore.UniversalWindowsPlatform.

    Edit: here's a list of missing types when using IL2CPP compared to Microsoft.NETCore.UniversalWindowsPlatform:

     
    Last edited: Dec 11, 2018