Search Unity

  1. Read here to learn more about our latest preview of the XR Interaction Toolkit.
    Dismiss Notice
  2. Click here to see what's on sale for the "Best of Super Sale" on the Asset Store
    Dismiss Notice
  3. Read here for Unity's latest plans on OpenXR.
    Dismiss Notice

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

Discussion in 'VR' started by chris_gsa, Oct 31, 2019.

  1. chris_gsa

    chris_gsa

    Joined:
    Aug 1, 2019
    Posts:
    9
    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:
    163
    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. chris_gsa

    chris_gsa

    Joined:
    Aug 1, 2019
    Posts:
    9
    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:
    163
  5. tomi-trescak

    tomi-trescak

    Joined:
    Jul 31, 2013
    Posts:
    76
    Hello, can you elaborate? I do not know which project you have opened? I simply do not see the files you talk about.

    I open the Unity soultion and there everythign is greyed out.
    I open the built project and there the cs files are not present

    Please help
     
  6. chris_gsa

    chris_gsa

    Joined:
    Aug 1, 2019
    Posts:
    9
    Hello,

    essentially, if you use Unity should create a Visual Studio Solution "YourProjectName.sln" in your project root folder, along with several C# project files (.csproj files). When you open this solution with Visual Studio (NOT the solution you generate during building with Unity and usually deploy), you should see all these C# projects in the solution explorer. One of them is called "Assembly-CSharp.Player". When I expand this project, there is a folder "Assets", which corresponds to the Assets folder within Unity Editor, and there you should find your scripts (see screenshot), without everything being greyed out.

    upload_2020-7-31_7-25-35.png

    I'm currentyl working with Unity 2019.3.10, and simply double-clicking one of my .cs script files in the Unity Editor opens a new instance of Visual Studio with this solution.

    Hope this could help.
     
unityunity