Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

UWP/HoloLens1 C# code editing with Unity 2019.x

Discussion in 'Windows Mixed Reality' started by unity_Py4F-tPKT23eNw, Oct 31, 2019.

  1. unity_Py4F-tPKT23eNw

    unity_Py4F-tPKT23eNw

    Joined:
    Aug 1, 2019
    Posts:
    2
    Hello,

    for using UWP/WinRT libraries in Unity apps, one must put them under ENABLE_WINMD_SUPPORT define in scripts:
    https://docs.unity3d.com/Manual/windowsstore-scripts.html

    However, this define greys out these code parts in the editor and disables functions like auto-complete or auto-formatting. Up until now, I solved this by generating the solution with Unity, opening it with Visual Studio and editing the code parts there, as they are not greyed out anymore, as described here:
    https://forums.hololens.com/discussion/10126/autocompletion-for-uwp-libraries-in-unity

    I recently upgraded my project to Unity 2019.3, and now with the IL2CPP scripting backend, the generated solution does not contain my .cs files anymore and I can't edit them in this way. I found this post describing the same problem:
    https://forum.unity.com/threads/how...support-code-efficiently.677911/#post-4537591
    but same as the OP, I can't find my C# scripts in the solution, all I find are C/C++ scripts. I'm using Visual Studio Community 2019 and have the Visual Studio Tools for Unity component added to my installation.
    Is there any way to have functions like autocompletion for UWP libraries in Unity 2019.x?

    Thanks!
     
  2. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    87
    Hey,

    This is an annoying problem that I also run into. Here are my suggestions for working around this VS limitation:
    • Use a different IDE with Unity like Rider or maybe VS Code
      • These tools appear to be superior to VS for actual coding, although full disclosure: I still mostly use VS for my work (been using it for 20+ years...old habits and such)
    • Install a formatting plugin for VS; ReSharper is highly recommended but isn't free, though perhaps you can find another free plugin to solve this problem
    • If you don't want to change/modify software: comment out the
      #if ENABLE_WINMD_SUPPORT ... #endif
      lines while writing your UWP code to allow formatting to work and then comment them out again when you're done
    • If you're writing a lot of UWP code, create a separate UWP Project in VS and code up your implementation there, and then copy or import this code into your Unity scripts
    I sure there are other options, but these are the solutions I tend to go with.
    I hope this helps.
     
  3. unity_Py4F-tPKT23eNw

    unity_Py4F-tPKT23eNw

    Joined:
    Aug 1, 2019
    Posts:
    2
    Hello timke,

    thank you for your reply and suggestions. I installed ReSharper (it comes for free with a Jetbrains student license). I'm not sure if this is what solved the problem, or if this was simply something I overlooked in the beginning, anyways, when I now open the solution in the Unity project folder (NOT the one in the "App" folder created after build), in the solution explorer I find a Project "Assembly-CSharp.Player", and in there are my C# scripts which i can edit as before with the .NET scripting backend. VS correctly detects WINMD support as enabled, therefore, code completion, automatic formatting etc. works for both UWP/WinRT libraries and Unity libraries!

    Maybe I should also mention that i built the Unity Projects with "Copy References", "Copy PDB files", "Development Build" and "Script Debugging" enabled, although I'm not entirely sure which effect this had.

    Tested with Unity 2019.1.11 and Unity 2019.3.0 and Visual Studio Community 2019. Hope this helps others as well.
     
  4. timke

    timke

    Unity Technologies

    Joined:
    Nov 30, 2017
    Posts:
    87