Unity Extension for Visual Studio Code - Compilation errors suppressed until you open file

I recently installed the Unity Extension for Visual Studio Code and configured my Unity project to use VSCode. It’s working seamlessly, except for one problem. If there are compilation errors in C# scripts, the errors are displayed in the Unity console, but are hidden in VSCode until you open the file containing the errors. With the old Unity package, every C# file containing errors would have their name highlighted in red automatically. With the new configuration, the filenames are displayed in white (or whatever the there-are-no-problems color is) until the file is opened, when the errors are detected and displayed in the editor and directory hierarchy.

Is there any way to configure Unity Extension for Visual Studio Code to indicate errors before opening the files?

What Unity version and which VS Code package?

Unity VS Code support has been deprecated, but then very recently a new package was announced or released as experimental/preview I think. So it matters which of these you are using.

Generally speaking I always recommend to stay clear of VSCode for Unity work, especially if you are a) a beginner because you get to have issues you needn‘t have for which you get little to no help and b) professionals as you will waste time (aka money) fighting issues few other people have and lack of tool support slowing down development, greatly offsetting the few seconds saved on launching VSCode compared to VS.

VSCode has some merits on OSX and is certainly useful on Linux.

I’ve been using VSCode for about 8 years both with Unity and other platforms. I’ve also been coding for >40 years. Not a beginner. :slight_smile:

The old Unity package is deprecated and I’m not using it. What I’m referring to is the new hotness…

Relevant versions…

  • Unity - 2023.1.8
  • VSCode - 1.81.1
  • C# Extension - 2.0.366
  • C# Dev Kit - 0.4.2
  • Unity Extension for Visual Studio Code - 0.9.0

Yeah I share my opinion here and there mainly in an effort to keep the number of foolish VSCode users to a minimum. At least until it‘s actually mature and MS has shown they really mean it this time (perhaps more so than their VS support for Unity). :wink:

Make sure you enabled (analyzer + compiler) background analysis for the whole solution (only open files by default) in VSCode settings:

And you can even “force” a problem-refresh by triggering a dotnet build.

1 Like

That sure looks like it should fix the problem, but sadly it doesn’t. I changed those settings for both User and Workspace. The errors still don’t get detected until you open the files.

What additional information should I provide to assist with figuring this out?

Please use Help/Report issue in VSCode so we can track this.

Any error message if you try to build from VSCode ? Perhaps you can find an error message in one of the output sources:
9226203--1288428--upload_2023-8-16_9-11-30.png

I tried on my side with several projects (small to mid size, and it was working as expected).

I created an issue…

Building yields very inconsistent results. After waiting for minutes, it finds lots of errors, none of which are cited in Unity. The following were found when my project contained no errors…
9227469--1288686--Problems.jpg

1 Like

I redownloaded my project from SCM to start from a clean slate. VS Code is finding compilation problems, although inconsistently. Here are some variants I’ve seen…

  • A few legit warnings are found along with 20 or so others that are not cited by Unity. This happens more often than not.
  • Hundreds of errors are cited having to do with items in my various script subdirectories not being found. None of the errors are cited by Unity.
  • Hundreds of errors are cited having to do with System.Void, System.int32, etc. not being found. None of the errors are cited by Unity.

What it never finds is my little syntax error, unless I open the file that it’s in.

I had both of these problems and I fixed them by setting both of the Background Analysis options in VS Code to fullSolution, updating the visual studio editor package in Unity, updating to .NET 8.0, deleting all of the files alongside the .csproj files in my projects root directory, and then regenerating project files with only the first two boxes checked under ‘Generate .csproj files for:’.

This has worked so far, though it takes a while for the error console to update for whatever reason.