Godot 4 .NET Setup under Linux

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By GenerationLost

Hi everyone,

I’ve waited to try out Godot for when C# support is solid and now seems to be the time. Unfortunately I don’t seem to get very far with my setup, as I can’t get .NET or VS Code to really work with Godot.

Currently I’m running Manjaro and I have to admit I’m not the most versed person in the Linux world, I simply prefer it over Windows and so far I’ve been doing fine. That just for a little background info.

So here’s what I did:

  1. Downloaded Godot from here.
  2. Started Godot and get the message about missing .NET (I thought I’ve installed it before):
Unable to load .NET runtime, specifically hostfxr.
Attempting to create/edit a project will lead to a crash.
Please install the .NET SKD 6.0 or later from https://dotnet.microsoft.com/en-us/download and restart Godot
  1. Installed .NET 6 via Microsoft’s scripts.
  2. Added variables to my .zshrc as described on Microsoft’s page:
export DOTNET_ROOT=$HOME/.dotnet
export PATH=$PATH:$HOME/.dotnet:$HOME/.dotnet/tools
  1. Started Godot again, no error message anymore.
  2. Created a test project, and tried to create a script. Got this message:
Failed to create C# project.

Output is the following:

Godot Engine v4.0.2.stable.mono.official (c) 2007-present Juan Linietsky, Ariel Manzur & Godot Contributors.
  modules/gltf/register_types.cpp:70 - Blend file import is enabled in the project settings, but no Blender path is configured in the editor settings. Blend files will not be imported.
  modules/mono/glue/runtime_interop.cpp:1303 - .NET Sdk not found. The required version is '6.0.16'.
--- Debug adapter server started ---
--- GDScript language server started ---
New Scene Root
Create Node
  modules/mono/glue/runtime_interop.cpp:1303 - System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
  File name: 'Microsoft.Build, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
     at GodotTools.ProjectEditor.ProjectGenerator.GenAndSaveGameProject(String dir, String name)
     at GodotTools.CsProjOperations.GenerateGameProject(String dir, String name) in /root/godot/modules/mono/editor/GodotTools/GodotTools/CsProjOperations.cs:line 13
  Transient parent has another exclusive child.
Attach Script

I’ve only found a few other posts on the internet where people seemed to have a similar, if not the same issue. Some suggested, the default path of .dotnet, which is /home/user/.dotnet is was trips up Godot and it should be in like /usr/bin/dotnet, but that didn’t make a difference either. I’ve also updated the path variable afterwards mind you and invoking dotnet from shell always gave the proper output.

So what am I missing here?

Another point would be getting VS Code to work. So I’ve got quite a few options here:

  1. Get VSCodium as flatpak…
  2. … or build it from AUR
  3. Get “the real” VS Code from flatpak…
  4. … or build it from AUR…
  5. …or download the archive from Microsoft directly.

I didn’t want to touch the AUR but tried the rest, none of them worked. So you can either set VS Code from the dropdown in the settings under Dotnet > Editor, or set an executable as external text editor under Text Editor > External, which I’ve tried as well. No idea where Godot is looking for VS Code and not finding it:

modules/mono/glue/runtime_interop.cpp:1303 - Cannot find code editor: VSCode
  editor/plugins/script_editor_plugin.cpp:2227 - Couldn't open script in the overridden external text editor

TL;DR I basically can’t setup Godot with .NET 6 and VS Code properly. Any help on this would really be appreciated. As of now it’s rather frustrating and I can’t find any other pointers online about this.

:bust_in_silhouette: Reply From: GenerationLost

The very simple solution for Godot to find the .NET SDK is to simply install it, in my case running Manjaro, with pacman. Simple and easy, no need for the Microsoft guide.

Getting VS Code to work remains an issue however. I’ve found the extension “C# Tools for Godot”, but simply installing it doesn’t seem to do much on it’s own. Most of all Godot still doesn’t know how to open scripts in VS Code and VS Code itself won’t provide any code completion, even if the project is open in Godot.


I am commenting only, as I only know for godot 3.x and as I am not using arch. But…

Have you build the .csproj file and the .sln? If not, you might have to click on “build” on the top right window of the godot editor first, after creating a new project. You only have to do that once.

About vscode (or codium) the good news is that they both work flawlessly once setup (although there is no debugger for C# on codium… But I’ve read that there was a workaround somewhere - not tested). If I remember correctly… the flatpak versions of vscode or codium don’t work with godot. For debian, the version of codium I have downloaded and that worked for me was the one from the db/rpm repository linked on the codium website. So… AUR for you? Maybe…^^

Then you’ll need to setup vscode or codium as your text editor by going in godot, Editor>Editor Settings>General tab>Text Editor>External, tick “Use External Editor”, copy the path to your text editor and add “{project} --goto {file}:{line}:{col}” as “Exec Flags”.

Finally, you have to download the appropriate extensions for vscode/codium: the official C# extension and, when it’ll be updated for godot 4 (if it is not already), the “C# tools for godot”, at least… I also have “mono-debug” and “godot-tools” but I am not sure if they are mandatory to have a working setup.

Oh, and you might have to reboot godot and vscode/codium once you set all that up.

Dostoi | 2023-05-11 20:34

Thanks for your reply!

Godot built the solution after finally being able to generate it in the first place, now that it can find dotnet.

As for VS Code, I’ve opted to go for Microsoft’s archive, as otherwise it’s only available as flatpak or from the AUR, as you said. But I didn’t want to mess with the AUR, so I’m using the “official” thing.
And thanks for your setup instructions for Godot! That’s the important part: VS Code needs to be setup just like you’ve described AND in the section "Editor>Editor Settings>Dotnet >Editor the option “External Editor” needs to be disabled! A bit un-intuitive but hey, it works now!

It seems that the official C# extension has not been updated for Godot 4, the last update was in September last year. However, code completion does seem to work so far! Only debugging is probably not properly set up, or set up for Godot 3, I don’t know what or how much at all has changed there, so maybe I’ll need to wait for an update there.

Anyway, thanks again for your help so far!

GenerationLost | 2023-05-12 09:53

:bust_in_silhouette: Reply From: GenerationLost

I’ve got it all to work with help of the community!
To summarize it all for my specific case, running Manjaro, for future reference:

  1. Install .NET 6 via pamac or pacman, DO NOT use Microsoft’s install script.
  2. Install VS Code from AUR. Only then Godot seems to recognize it when setting it under Editor > Editor Settings > Dotnet > Editor.
  3. Install “C# Tools for Godot” extension in VS Code as you normally would.
  4. Use the following configuration for debugging to work: Support for Godot 4 + mono · Issue #43 · godotengine/godot-csharp-vscode · GitHub

For anyone struggling with this: I am using Microsoft’s install script and the $HOME/.dotnet install with Godot.

Simply setting the envvar DOTNET_ROOT="$HOME/.dotnet" when launching Godot did the trick. I accomplished this in my .desktop file by changing the Exec line to this:

Exec=env DOTNET_ROOT="$HOME/.dotnet" /usr/bin/godot

Make sure the /usr/bin/godot part matches where you have your Godot executable and happy gamecrafting.