Visual Studio doesn't compile the code while editing.

I had Visual studio already installed with .NET for C# Console and Form applications.
After that I installed unity, and added visual studio as the external code editor in Preferences → External Tools.
I opened up a script and realized it doesn’t compile. I closed visual studio and unity.
Opened Visual Studio Installer, Clicked on modify, added game development with Unity.
Went back to Unity, opened external tools, refreshed the visual studio, regenerated project files.

Opened the script by double clicking on Unity, it opened up Visual Studio, I made an error on purpose.

if (timerInterval > 0 &&) // AND needs another statement or check
{
//Code
}

Visual Studio shows no errors, Unity does.

Did you actually execute the „Build Solution“ or similar menu item in VS in order to start compilation?
VS doesn‘t automatically start compilation when you save a file.

Try opening the C# project in Assets/Open C# project in the Unity editor instead.

Visual Studio should react to the error on typing. No need to compile. :slight_smile:

1 Like

There’s Attach instead of Compile, and it should be automatically telling me my errors.
That’s what it did on another computer when I used to code there.

You mean “Right click → Open C# Project” in the asset browser?
If so, it does the same thing. And my errors aren’t visible until I save the code and go back to unity.

Well, there’s probably a problem with Visual Studio then. Are you sure you installed every component needed for it to work properly with Unity? I’m not using Windows, so I don’t remember exactly what needs to be installed but you should take a look at that: https://learn.microsoft.com/en-us/visualstudio/gamedev/unity/get-started/getting-started-with-visual-studio-tools-for-unity?pivots=windows.

Yes I already installed it. (It only shows “Game development with Unity” to install in that link)
I will try “repairing” and report back if it works.

Repairing has no effect on this problem.

Visual studio still doesn’t give out errors.
When I save and go back to unity though, it tells me the errors.

Momentarily I do not think there’s a difference between using Np++ and Visual studio since they both make code suggestions, but they do not understand errors.

Just in case, did you restart your computer after installing, repairing, etc?

Yup. Ofc