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.


❤️

@dbidwell94
Copy link

So mine failed on step 4 with the error:

/home/dbidwell/Documents/Games/Tycoon/Tycoon.csproj(0,0): SDK Resolver Failure: "The SDK resolver "NuGetSdkResolver" failed while attempting to resolve the SDK "Godot.NET.Sdk/3.3.0". Exception: "NuGet.Packaging.Core.PackagingException: Unable to find fallback package folder '/home/dbidwell/.local/share/godot/mono/GodotNuGetFallbackFolder'.

I have dotnet-sdk 6.0 as well as mono installed on my system.

@SliverLIVE
Copy link

Should be updated for 4.0 ;)

@paulloz
Copy link
Author

paulloz commented Mar 2, 2023

Should be updated for 4.0 ;)

Yeah, I know. Will do when I have the time 🙂

@DoofusLoofus
Copy link

Help, I was messing around and accidentally did the first 3 steps and now I can't run my game, is there a way to undo this?

@paulloz
Copy link
Author

paulloz commented Mar 4, 2023

Help, I was messing around and accidentally did the first 3 steps and now I can't run my game, is there a way to undo this?

@DoofusLoofus I'm not sure what your issue is? Nothing in this guide should be susceptible to making your game impossible to run. Gist comments probably aren't the optimal way to communicate, feel free to reach out to me if you still have issues (contact info on my GitHub profile).

@Meteoroetem
Copy link

Yayy!! Thank you :)

@DoofusLoofus
Copy link

Help, I was messing around and accidentally did the first 3 steps and now I can't run my game, is there a way to undo this?

@DoofusLoofus I'm not sure what your issue is? Nothing in this guide should be susceptible to making your game impossible to run. Gist comments probably aren't the optimal way to communicate, feel free to reach out to me if you still have issues (contact info on my GitHub profile).

Well, I had a game I was working on in Godot without any use of C#, however, once I accidentally did the first three steps any attempt to run the game would result in a build error. I did fix the problem though, I just needed to delete the C# and sln files in the game's folder though maybe there's some way that's gonna backfire later, it's fine for now. Either way thanks for trying to help.

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