Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Official Microsoft previews Unity extension for Visual Studio Code

Discussion in 'Code Editors & IDEs' started by simon-elliston-ball, Aug 3, 2023.

  1. ryanslikesocool

    ryanslikesocool

    Joined:
    Jul 31, 2016
    Posts:
    49
    This worked for me, thanks! I had to manually add the "dotnet.defaultSolution" key to .vscode/settings.json. Regenerate Project Files in Unity settings didn't include it for some reason.
     
    sailro likes this.
  2. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Replace the legacy configuration entry with this one:

    Code (csharp):
    1.  
    2.  {
    3.             "name": "Attach to Unity",
    4.             "type": "vstuc",
    5.             "request": "attach"
    6.  }
    7.  
    And you should be good. 'vstuc' type is the important change, 'unity' was the type used by the legacy Unity debugger, 'vstuc' is used for the new Microsoft' one.

    When we generate project files, we create this launch.json with proper settings, but if the file exists we are doing nothing for now. We are thinking of auto-fixing legacy configurations and other incompatible settings in the next VS Editor package.
     
    Last edited: Aug 23, 2023
    LilGames, MousePods and Nelvin123 like this.
  3. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    562
    Fantastic! That worked.
     
    sailro likes this.
  4. JHobsie

    JHobsie

    Joined:
    Aug 3, 2015
    Posts:
    9
    Correct me if I'm wrong as the MS licencing options can be a bit awkward to navigate beyond the 2 monthly subscriptions.

    The C# Dev Kit for VS Code is not actually included in the Professional and Enterprise monthly subscription but is only included in the 'Standard + GitHub Enterprise' subscriptions which cost a lot more (I think ~£1400/£6000 a year for pro/enterprise).

    So if you fall into the category of needing a pro licence or more it would be way cheaper to use Visual Studio with a monthly sub rather than Visual Code + Official Unity Plugin? Which seems backwards.
     

    Attached Files:

  5. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    562
    So I've been using the debugger and it's been wonderful being able to Step Into and Watch variables again. However starting about 2 days ago, the time it takes for Unity to reload assemblies and compile code when the debugger is activated is really long. Yesterday I noticed all the Microsoft Visual Code extensions had updates waiting so I updated them but that hasn't changed anything. What should I be looking at?
     
    Last edited: Aug 30, 2023
  6. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Hi!

    Perhaps you should double-check your breakpoints. If you keep advanced ones like function breakpoints, exception breakpoints or breakpoints with conditions, we have to disable specific optimizations (like type load filtering) or use a lot of evaluations that can impact the global performance.

    It is also possible that your code started throwing a lot of exceptions and this is known to kill the performance especially when debugging. For that you can use an exception breakpoint to find the culprit.
     
    pKallv and LilGames like this.
  7. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    562
    Fantastic! I clicked "Clear all breakpoints" and then only added 1 breakpoint. Hit the debug > button, hit Play in Unity and it all started right up within 2 seconds.
     
    sailro likes this.
  8. Deleted User

    Deleted User

    Guest

    This is awesome!!! Thank you so much! Now I don't need a Rider subscription and can use vscode for everything!
     
    MousePods and sailro like this.
  9. Deleted User

    Deleted User

    Guest

    Do I really need to sign in with Microsoft to use the C# dev kit?

    Capture d’écran_2023-09-04_08-22-11.jpg
     
  10. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    432
    Deleted User likes this.
  11. Deleted User

    Deleted User

    Guest

    Nice, after I created a variable, it suggested the next one. :)

    Capture d’écran_2023-09-04_17-51-31.jpg
     
  12. Deleted User

    Deleted User

    Guest

    But it doesn't know Vector2... :(

    Capture d’écran_2023-09-04_18-17-59.jpg
     
  13. jasonboukheir

    jasonboukheir

    Joined:
    May 3, 2017
    Posts:
    81
    I'm really enjoying using vscode on my project with Copilot -- it's saved me much typing.

    One slowdown is that my project is a multi-root project, and I like to refer to my other files while i'm working in Unity. I have a workspace file in my root unity project, but when I double click a c# script, Unity opens the folder, and not the workspace.

    Is it possible for me to make it so that Unity will open a particular workspace file instead of the project folder when I double click a C# script? Is there a way for me to set default workspace settings in vscode so that if it opens a folder it automatically opens the workspace?

    It presents another issue, where I have to copy my workspace settings between the folder and my workspace file. For example, I use conventional commits extension, and I have duplicated default scopes in both the workspace and .vscode/settings.json files.
     
  14. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    saskenergy and jasonboukheir like this.
  15. Deleted User

    Deleted User

    Guest

    Well, it seems that rebooting was necessary. Today, it knows Vector2.

    Capture d’écran_2023-09-05_08-36-08.jpg
     
    pKallv and LilGames like this.
  16. PyrateAkananto

    PyrateAkananto

    Joined:
    May 8, 2018
    Posts:
    10
    So as somebody who prefers Visual Studio Code over Visual Studio Professional and who is an "enterprise" user according to Microsoft's license terms I am now forced to buy a license for Visual Studio Professional to use this new "Unity" extension from Microsoft for Visual Studio Code? Like, seriously?!

    To be honest I currently am really frustrated about the way this is going. So far .NET and C# and Visual Studio Code had been a joy to work with and were great to be recommended to others because of their open source origin and their permissive licenses. This new licensing terms for the new closed source extensions are complicated and confusing and basically try to shove "enterprise" users over to the full-but-expensive(-and-bloated) Visual Studio Professional.
     
    jasonboukheir likes this.
  17. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,166
    After the Visual Studio for Mac announcement I have decided to try out the code editor before turning to Rider.

    Is there a list of usable and nice to have extensions to install?

    ...also can someone point me to a good, and recent, tutorial using it with Unity3d and, what I think, is the recent additions?
     
  18. Nelvin123

    Nelvin123

    Joined:
    Apr 4, 2014
    Posts:
    5
    These 4 are my favourites (besides whatever programming language/project related plugin I use, depending on what I'm working on)

    https://marketplace.visualstudio.com/items?itemName=usernamehw.errorlens
    https://marketplace.visualstudio.com/items?itemName=aaron-bond.better-comments
    https://marketplace.visualstudio.com/items?itemName=alefragnani.Bookmarks
    https://marketplace.visualstudio.com/items?itemName=ms-vscode.hexeditor
     
    pKallv likes this.
  19. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    562
    It's just coding. I'm not sure what tutorials you need. Your coding IDE should:
    - highlight syntax
    - detect typos and errors
    - autocomplete is useful
    - allow right-clicking to view Definitions (eg: You right click on a function name in your code, select "Go To Definition" and it should show you/take you to that function. Same for variables and other definitions.
    - Rename Symbol is how to rename a var or function such that it changes EVERYWHERE in your project code files.
    - and of course a working debugger

    Extensions:
    - Unity (from Microsoft)
    - Intellicode for C# Dev Kit
    - C# Dev Kit
    - C#
    - .Net Runtime Install Tool

    And then here's one I installed because I got used to this feature when I used to code Actionscript in Flash :
    Duplicate selection or line by Greg Bacchus
    https://marketplace.visualstudio.com/items?itemName=geeebe.duplicate
    You CTRL-D and it duplicates the line of code or selection. Very useful shortcut.
     
    Last edited: Sep 7, 2023
    pKallv and Deleted User like this.
  20. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,166
    Now I have used VSC or a few days and I must say that I like it. Will also test Rider but as I feel now it must be quite better if I should use it. However, I have never used rider so maybe it is.
     
  21. Deleted User

    Deleted User

    Guest

    I just experienced some problems with autocomplete. It should be said somewhere that for VS Code autocompletion to work properly, the Unity package "Test Framework" must be installed in the project. I didn't get any warning of any kind when I deinstalled it. Lesson learnt.
     
  22. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    Indeed, Test Framework is a dependency of the VS Editor Package:

    upload_2023-9-10_10-6-45.png

    I believe it was possible to remove dependencies with previous Unity version (it is clearly an issue), but I just tested with 2022.3.f1 and you cannot do that anymore -hopefully-.

    upload_2023-9-10_10-8-58.png
     
    MousePods likes this.
  23. Deleted User

    Deleted User

    Guest

    Hopefully. I'm using version 2021.3.
     
  24. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,166
    I will go for VSC at this point. It is really good, and free.
     
    Nelvin123 and Deleted User like this.
  25. Deleted User

    Deleted User

    Guest

    Welcome! :)
     
    pKallv likes this.
  26. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,166
    Is anyone aware of an extension that automatically format the code when you add a {?

    Example: I put an if statement in front of a code line and remove the } that is automatically added and place it on the line after the code line. I would like VSC to format so the code line, or whatever is in-between the {} is tabbed to the correct position.
     
    LilGames likes this.
  27. coffeebuyer

    coffeebuyer

    Joined:
    Jan 31, 2023
    Posts:
    9
    Does it work well with Unity DOTS, ECS?
     
  28. AnthonySlay

    AnthonySlay

    Joined:
    Nov 16, 2015
    Posts:
    2
    @jbevain-msft is there a github issue or roadmap we can follow for this particular feature for VSCode? I've been searching we web for days, and you are the only person that knew the answer to this question. So, I figure you would probably have the inside knowledge of when they might get done.
     
  29. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,136
  30. AnthonySlay

    AnthonySlay

    Joined:
    Nov 16, 2015
    Posts:
    2
  31. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    118
    I had zero problems migrating to the new extension on my laptop, but it simply cannot load the projects on my other machine. I've ensured I have the same versions of dotnet and all of the extensions installed on both machines: on one machine, there's no problem, and on this one, the projects always fail with:

    Code (CSharp):
    1. 2023-11-14 10:26:28.006 [info] It was not possible to find any compatible framework version
    2. The framework 'Microsoft.NETCore.App', version '6.0.0' was not found.
    3.   - No frameworks were found.
    4.  
    5. You can resolve the problem by installing the specified framework and/or SDK.
    6.  
    7. The specified framework can be found at:
    8.   - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=6.0.0&arch=x64&rid=win10-x64
    9.  
    10. 2023-11-14 10:26:30.579 [info] Project system initialization finished. 0 project(s) are loaded, and 16 failed to load.
    I've deleted and regenerated the csproj files many times in Unity, also confirmed they look the same on both machines. .NET is absolutely installed. I can even get things working in Visual Studio if I switch my external tools over to that in Unity, but I would prefer to stick with VSCode.

    Does anyone know how I can rollback to the old deprecated extension? I had everything working for the last few years with VSCode if I simply never upgraded from com.unity.ide.vscode v1.1.3.
     
  32. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    118
    In case this is helpful, here's the output from the C# Dev Kit:

    Code (CSharp):
    1. Starting Spawn .NET server...
    2. Starting Open a solution...
    3. Starting Open a solution with environment service...
    4. Starting Clear environment...
    5. Using local .NET runtime at "c:\Users\User Name\AppData\Roaming\Code\User\globalStorage\ms-dotnettools.vscode-dotnet-runtime\.dotnet\7.0.13~x64\dotnet.exe"
    6. .NET server started and IPC established in 779ms
    7. Completed Spawn .NET server (1111ms)
    8. Completed Clear environment (1374ms)
    9. Completed Open a solution with environment service (1397ms)
    10. Starting Restore solution...
    11. Completed Open a solution (1404ms)
    12. Starting NuGet restore for the solution.
    13. Starting command: "dotnet.exe" restore C:\Users\User Name\Documents\GitHub\Little-Nemo\Little-Nemo.sln --interactive...
    14. Completed command: "dotnet.exe" restore C:\Users\User Name\Documents\GitHub\Little-Nemo\Little-Nemo.sln --interactive (997ms)
    15. Completed NuGet restore.
    16. Completed Restore solution (998ms)
    And the output from C# Dev Kit - Test Explorer:

    Code (CSharp):
    1. Created Test Controller
    2. unable to create test controller for c# extension: Error: Unable to locate the dotnet sdk.
    Another thought: on the computer that this works, I have no spaces in my username, in the computer that it does not work I do have a space in my username. I saw that there was a bug in an earlier version of this extension that it broke when encountering spaces, but I'm on the latest.

    Edit: I just created a new user with no spaces in the name and installed everything there and I'm seeing the same issue.
     
    Last edited: Nov 14, 2023
  33. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    @diesoftgames it seems C# Dev Kit can find the *runtime* v7 (for its own use), but not the *SDK* v6 for the project dependencies.

    Are you using the latest VS Editor package in your Unity project ? (latest should be 2.0.22). It is mandatory if you want to properly generate projects for Visual Studio Code.

    Could you please double check that everything is properly setup using this doc:
    https://code.visualstudio.com/docs/other/unity

    Then if you still hit an issue, could you please create a ticket here: https://github.com/microsoft/vscode-dotnettools

    Thanks!
     
  34. diesoftgames

    diesoftgames

    Joined:
    Nov 27, 2018
    Posts:
    118
    Yup, already done and done. I have everything set up according to the docs and posted an issue in that GitHub repo yesterday. Thank you!

    Edit: After battling this for a full day trying to get it to work again, I had to give up and migrate to using Visual Studio Community instead of VSCode, but I would love to be able to return to VSCode so I'll be keeping an eye on that issue.
     
  35. mkg2w

    mkg2w

    Joined:
    Aug 19, 2013
    Posts:
    54
    Hi,
    Seeking some clarity on the licensing requirement with Visual Studio Code :

    As per https://unity.com/how-to/debugging-...de#install-visual-studio-editor-unity-package, it's possible to use the the new Unity package with Visual Studio Code, Microsoft's Open Source offering.

    However, the new package uses the C# Dev Kit, which, per this note, https://code.visualstudio.com/docs/csharp/cs-dev-kit-faq#_who-can-use-c-dev-kit, is a paid solution .

    Can the new plugin be used in Visual Studio Code, on the same licensing terms as Visual Studio Code ?
     
  36. sailro

    sailro

    Microsoft

    Joined:
    Jul 30, 2014
    Posts:
    167
    C# Dev Kit and the Unity extension for Visual Studio Code are built on the same foundations as Visual Studio, they are licensed under similar terms as Visual Studio is.

    This means they are free for individuals, academia, and open-source development, just like the terms that apply to Visual Studio Community. For organizations, C# Dev Kit and its family of extensions are included with Visual Studio Professional and Enterprise subscriptions, as well as GitHub Codespaces.

    For additional details, please refer to the license terms.
     
    Harry-Wells likes this.
  37. mkg2w

    mkg2w

    Joined:
    Aug 19, 2013
    Posts:
    54
    Thank you @sailro .
    Can you confirm that Organisations need to use a Visual Studio Professional / Enterprise subscription, if they intend to use the C# Dev Kit, even in Visual Studio Code ?

    Additionally, Microsoft has declared they will stop supporting Microsoft VS for the Mac in August 2024. What is the recourse for Unity developers on Mac?
     
    Last edited: Dec 22, 2023
  38. sudarshanT

    sudarshanT

    Joined:
    Nov 23, 2023
    Posts:
    4
    It solved my problem. Thank you.