Microsoft previews Unity extension for Visual Studio Code

We are delighted to announce that Visual Studio Code support for Unity is coming back in a new improved form.

In June our friends at Microsoft launched the C# dev kit, which gives Visual Studio Code users access to some of the powerful C# tools more familiar to full Visual Studio users. Today, they are opening a preview of the Unity Extension for Visual Studio Code which brings the Unity experience for Visual Studio into Visual Studio Code.

The extension supports code editing powered by Roslyn for better Intellisense and AI assisted coding, backed up by the Unity Roslyn Analyzers to give you code suggestions specific to Unity. It also helps with debugging, running in the Unity Editor or standalone players. Use the new ā€œAttach Unity Debuggerā€ command in Visual Studio Code, and set a breakpoint to get into the VS Code debugging experience.

The new Unity Extension for Visual Studio Code is built on the same foundations as the Visual Studio Tools for Unity and the C# Dev Kit. It is also licensed in the same way as regular Visual Studio. This means it is 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. Please refer to Microsoftā€™s license terms for details.

Getting Started
The extensions require Unity 2021 or greater. All you need to do is to install the ā€œVisual Studio Editorā€ package (version 2.0.20 or above) in your Unity project. Note that you should NOT use the deprecated version for Visual Studio Code. The new extension uses the same backend as the full Visual Studio. If you have the old package installed, itā€™s best to remove it first.


Once the Unity side is ready, you can just install the Unity Extension in Visual Studio Code, which will bring in dependencies, including C# Dev Kit and C# extensions if you donā€™t already have them.

Donā€™t forget that you can also choose Visual Studio Code as your external script edtor in the Unity Editor preferences under External Tools.


If you want to learn more about this extension, and provide feedback direct to the Microsoft team, you can do that in the Visual Studio Code editor itself with the Help > Report Issue function. Also check out their blog for more detail on this release.

31 Likes

Thanks Microsoft for the new debugger.

Also, ā€œFor developers who prefer using a fully featured IDE, we continue to recommend using Visual Studio with the Visual Studio Tools for Unity which together deliver a feature rich development experience tailored to Unity.ā€

2 Likes

Just tested it and everything works as expected. Itā€™s also pretty fast compared to the previous Unity extension. Huge thanks to the people who worked on this! Now we have an alternative to Rider for Linux.

Itā€™s also cool that it offers syntax coloration for .asmdef, .shader, .uss, and .uxml files. Though it doesnā€™t offer full support, for example, using random variable names in shaders doesnā€™t produce any errors. This is the start at least.

Can we also have official support for common snippets like this extension? Nothing wrong with it, just makes it very convenient to have all functionality in one extension.

4 Likes

@simon-elliston-ball since the Visual Studio Editor package can now generate SDK-style project. Please use it for Visual Studio too. While I mainly use Visual Studio, I do have a need to use VSCode side-by-side sometimes. But if I select VSCode as the External Scripting Editor just to regenerate the project files, I canā€™t work normally on Visual Studio until the next regeneration. And itā€™s too annoying.

Yay great news! I very much respect and appreciate this decision. Many thanks to everyone involved!
Also the timing of this is incredible! Just as was pondering whether upgrading to the next LTS would be more important than my long-time VSCode setup.

1 Like

I really donā€™t like this update showing that methods are unsed!
9194615--1281665--upload_2023-8-4_12-35-39.png

There is probably something missing for your setup. I didnā€™t experience this though.

1 Like

Earlier versions of the C# extensions had some issues with analyzers, please make sure:

  • Your C# and C# Dev Kit extensions are upgraded to the latest version:

  • C# (v2.0.320)

  • C# Dev Kit (v0.4.2)

  • Youā€™ve restarted VS Code, just in case.

3 Likes

Not working for me. Now it does not show the erros in the code in VS code. And it does not autocomplete either. Basically now it does nothing but showing the outline and counting the references to the methods. Using VS code in linux, Unity 2021. Until know everything was working ok.
After some time waiting this is what it says:
2023-08-04 23:02:14.018 [info] Project system initialization finished. 0 project(s) are loaded, and 54 failed to load.
Iā€™m going to the old version.

2 Likes

I got it fully working on both Windows and Ubuntu 23.04. There are a couple of requirements you need to do to have it working:

  • For Linux users, you need to install VS Code using apt or dnf. I installed mine using Snap and Unity canā€™t detect it.

  • Use the latest versions of C# (v2.0.320) and C# Dev Kit (v0.4.2) as @jbevain-msft mentioned above.

  • Install .NET 7 (not version 6, I tried it and it doesnā€™t work).

  • Install the Visual Studio package in the Unity package manager (NOT the Visual Studio Code package). The package MUST be version 2.0.20 or above. Iā€™m currently on the latest 2022 LTS version of Unity, I donā€™t know if the previous versions have the latest package version.

  • Open your project from the Unity editor. Make sure youā€™ve set Unity to open using VS Code in your preferences (for Linux users, if the VS Code option does not pop up, follow step 1). Opening it from the Unity editor sets some things in VS Codeā€™s side.

Thatā€™s all you need to do and it should work. Assuming youā€™ve properly set it up, those squiggly lines under Start, Update, etc. shouldnā€™t show up. Make sure there are no errors on the extension (check on bottom left indicator).

I did have a small issue on the Linux side though, VS Code keeps complaining about how it canā€™t watch all the files in my project due to hitting fsnotify limits. Iā€™ve already set my fsnotify limit to max and the issue still persists. Rider does not have this issue on the exact same project so this issue probably on VS Code. Even with that, intellisense seems to work fine so I dunno?

7 Likes

Thank you. Doing ā€œ3 Install .NET 7ā€ now itā€™s working.

3 Likes

Create a .editorconfig file in your projectā€™s directory and add this to it.

#Ignore IDE0051: Remove unused private members
[*.cs]
dotnet_diagnostic.IDE0051.severity = none

This is a requirement for Unity projects IMO.

1 Like

The Unity extension ships with our suite of analyzers and suppressors that should remove the IDE0051 for Unity types.

If there are cases that weā€™re missing or that are still showing up, weā€™d love to hear about it to provide a better experience.

2 Likes

References of fields are gone. There are only references for methods, but fields references are missing. Also there are constantly advices to make some fields with readonly modifier. I checked all versions of extensions, version of dotnet and etc. All versions are up-to-date. I donā€™t know whats the reason of these problems9197093--1282385--upload_2023-8-6_0-30-54.png

1 Like

@jbevain-msft The current version canā€™t autocomplete MonoBehaviour messages (Start, Awake,ā€¦)

We have that feature in Visual Studio and it hasnā€™t made it into the Unity extension for Visual Studio Code yet.

1 Like

I think that might be a feature difference between the previous Omnisharp based C# extension and the new one that the .NET just released. Let me talk to the team this week to better understand the plan around this.

I have such problem here with Visual code + Unity

This problem appeared either because I tried to install the new Unity Extension (but I have 2020.3), or because of Visual Code auto-updates, or God knows what else.
Can you tell me if I can roll back my Visual Code version to what it was just 3 days ago?
I was fine with the old Visual code, plus Iā€™m on a tight deadline :frowning:

After this update, the reference of field is gone except the methods. And there are some weird readonly modifier advices for private fields.

9199709--1283018--upload_2023-8-7_17-53-57.png

1 Like

Open the extensions panel and right click on the C# language support extension and select ā€˜Install Another Versionā€™. You probably want V1.26.0.

3 Likes