Skip to content

Instantly share code, notes, and snippets.

@paulloz
Last active March 28, 2024 03:08
Show Gist options
  • Star 46 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulloz/30ae499c1fc580a2f3ab9ecebe80d9ba to your computer and use it in GitHub Desktop.
Save paulloz/30ae499c1fc580a2f3ab9ecebe80d9ba to your computer and use it in GitHub Desktop.
Visual Studio Code and C# code completion and debugger for Godot

Visual Studio Code and C# code completion and debugger for Godot

Ok, this is a quick document to guide you through the setup of a Godot project in Visual Studio Code.
I'll assume you have a working C# environment installed. Note that on Linux, you might need to install Mono for everything to work fine with Godot 3.x.

1. Install the necessary extensions

First off, make sure you have the following extensions installed and active in Visual Studio Code:

At this point (after you restart the editor) you should already be able to use code completion for C#, except for anything coming from the Godot namespaces.

completion_1

2. Create a new project in Godot

The next step is to actually create a project in Godot.

3. Generate the C# solution

In Godot's menus: go into Project > Tools > C#, and click on Create C# solution.

generate_solution

After a few seconds and some loading bars, you should see a new menu appear in the bottom dock. It opens the panel where you'll see build reports for the C# project.

new_menu

If you don't see this button, check your project for a .csproj and a .sln file. They should already be here and you can skip this step.

4. Build the project once

In the new panel, click on Build > Build Project. Everything should go smoothly. After all, the project is empty. Once the build is done, let's proceed to the next step.

build_project

5. (Re)Start Omnisharp in Visual Studio Code

Back in Visual Studio Code, open up the command palette (Ctrl+Shift+P), search for the OmniSharp: Restart omniSharp command and run it.

restart_omnisharp

It may ask you to choose a project, select the .sln option.

project_selection

/!\ It is very important that you do not click out this box without selecting anything. If you do so: do not panic and search for the OmniSharp: Select Project command in the palette.

select_project

Once you've selected your project and OmniSharp is properly started, the name of the project should appear in the lower left corner of Visual Studio Code. The small flame on its left is the icon for OmniSharp, it lights up when the service is busy.

status_bar

6. Go check everything work

Once all of this is done, everything should work fine.

completion_2

7. Bonus step, setting up the debugger

7-A. For Godot 3.x

Head out to the Run and Debug menu in Visual Studio Code and you'll see a small link titled create a launch.json file.

create_launch_json

Click on it and a menu appears, asking you to select an environment. Choose C# Godot.

select_environment

Once it's done, the Run and Debug menu will change and you'll be able to start debugging with the Play in Editor button.

start_debugging

7-B. For Godot 4.x

Create .vscode/launch.json and .vscode/tasks.json files, like for any other C# project. If you need, you can find examples here and here.


❤️

Copy link

ghost commented Mar 11, 2023

Thank You, this was very helpful. It worked for me in Version 4.0 too.

@zaneshaw
Copy link

Is it possible to setup auto solution building? I'm needing to build everytime I make a change for it to take effect.

@nathanpovo
Copy link

Is it possible to setup auto solution building? I'm needing to build everytime I make a change for it to take effect.

@zaneshaw use dotnet watch build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment