Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Godot 4 + mono #43

Open
nonunknown opened this issue Apr 10, 2022 · 28 comments
Open

Support for Godot 4 + mono #43

nonunknown opened this issue Apr 10, 2022 · 28 comments
Assignees
Labels
bug Something isn't working

Comments

@nonunknown
Copy link

OS/device including version:

Linux Manjaro KDE

Issue description:

I'm trying to use Vscode with Godot 4 + mono, but the options for C# doesnt appear as described in the README.MD

@nonunknown nonunknown added the bug Something isn't working label Apr 10, 2022
@raulsntos
Copy link
Member

raulsntos commented Apr 10, 2022

There are some changes in 4.0 that break the extension, so this issue is probably a duplicate of #38. But since for Godot 4.0 we plan to move to .NET 6.0 this will probably not be fixed.

I have a draft PR #39 that should fix the extension to work with the current master that still uses Mono but as I said it won't be merged, so as a workaround you can compile the extension yourself using my branch and it should work.

@Seikho
Copy link

Seikho commented Sep 25, 2022

Do you think it would be feasible to finish this now that the Godot 4 beta has been released?

@timshannon
Copy link

@Seikho FWIW, I was able to use the microsoft / omnisharp c# extension fine for debugging, you just have to manually setup the config for it.

@Seikho
Copy link

Seikho commented Sep 26, 2022

Thanks @timshannon. Could you be able to provide an example of this for me?

@timshannon
Copy link

I always use attach personally, so that config is pretty straightforward:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach"
        }
    ]
}

For any other setup where you are launching godot yourself, you'll need to point at wherever you keep your Godot instance.

@jolexxa
Copy link

jolexxa commented Sep 26, 2022

Likewise, if you need to be able to debug immediately once the app starts, you can use the below launch.json file. Make sure you've setup a GODOT4 environment variable which points to Godot on your machine.

{
  "version": "0.2.0",
  "configurations": [
    // For these launch configurations to work, you need to setup a GODOT4
    // environment variable. On mac or linux, this can be done by adding
    // the following to your .zshrc, .bashrc, or .bash_profile file:
    // export GODOT4="/Applications/Godot.app/Contents/MacOS/Godot"
    {
      "name": "Play",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${env:GODOT4}",
      "args": [],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
    }
  ]
}

And the tasks.json file to build before each launch:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "command": "dotnet",
      "type": "process",
      "args": [
        "build"
      ],
      "problemMatcher": "$msCompile",
      "presentation": {
        "echo": true,
        "reveal": "silent",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
      }
    }
  ]
}

If you need more, I keep the most up-to-date versions that I use for VSCode here.

@neikeq
Copy link
Contributor

neikeq commented Sep 26, 2022

@timshannon You're not on Linux, right? Only the launch option worked for me on Linux. I couldn't get attach to work.

@timshannon
Copy link

@neikeq Yeah I'm on linux (Ubuntu Ubuntu 22.04.1 LT). Works fine for me.

@Seikho
Copy link

Seikho commented Sep 27, 2022

Thanks, @timshannon and @definitelyokay ! This works beautifully. Attach, Play and build all worked.
FWIW, I'm on Ubuntu 20 and 22 as well.

@rafaelgdp
Copy link

Likewise, if you need to be able to debug immediately once the app starts, you can use the below launch.json file. Make sure you've setup a GODOT4 environment variable which points to Godot on your machine.

{
  "version": "0.2.0",
  "configurations": [
    // For these launch configurations to work, you need to setup a GODOT4
    // environment variable. On mac or linux, this can be done by adding
    // the following to your .zshrc, .bashrc, or .bash_profile file:
    // export GODOT4="/Applications/Godot.app/Contents/MacOS/Godot"
    {
      "name": "Play",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${env:GODOT4}",
      "args": [],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
    }
  ]
}

And the tasks.json file to build before each launch:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "command": "dotnet",
      "type": "process",
      "args": [
        "build"
      ],
      "problemMatcher": "$msCompile",
      "presentation": {
        "echo": true,
        "reveal": "silent",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
      }
    }
  ]
}

Thank you so much! I just tested this on my Windows 11 laptop and it worked like a charm! Debugging on VSCode is working with this config! The only thing I did differently was I did not use an environment variable for Godot 4 in the "program" field but rather just pasted the full path of the Godot 4 beta 3 executable I downloaded.

@lorenzo-arena
Copy link

If I'm understanding correctly by using those configurations with coreclr mono is not needed on Linux anymore, correct?

@alexaisok
Copy link
Contributor

Since Microsoft's C# extension can be configured to launch and debug Godot 4 projects (above), will this extension be deprecated going into Godot 4?

@Seikho
Copy link

Seikho commented Dec 12, 2022

The extension is intended to also provide other auto-completions as well. I haven't had those working for a while.
I think it'd be helpful if the extension could generate launch and task configurations for Godot 4.

@alexaisok
Copy link
Contributor

alexaisok commented Dec 12, 2022

The extension is intended to also provide other auto-completions as well. I haven't had those working for a while. I think it'd be helpful if the extension could generate launch and task configurations for Godot 4.

Generating launch and task configs would be handy though I found it pretty trivial to set them up manually. An attach launch config that automatically detects the appropriate process would be particularly convenient because currently you have to select the process manually when doing a coreclr attach. What autocomplete issues are you having? Using Godot 4 with the Microsoft/Omnisharp C# extension alone has been seamless for me so far.

@Seikho
Copy link

Seikho commented Dec 12, 2022

Specifically the node paths. I can't recall if I've had node path completion working in Godot 4 at all, but I haven't really expected it to since it's still in beta.

@M1N1M3
Copy link

M1N1M3 commented Feb 25, 2023

{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "/mnt/internal/main/dev/game-dev/godot/engine/godot",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false
},
{
"name": "Attach",
"type": "coreclr",
"request": "attach"
}
]
}

Can anyone confirm if they have this working with the open vsx muhammad-sammy.csharp extension? When I run the launch task I get this error in the debug console:

Could not execute because the specified command or file was not found.
Possible reasons for this include:

  • You misspelled a built-in dotnet command.
  • You intended to execute a .NET program, but dotnet-/mnt/internal/main/dev/game-dev/godot/engine/godot does not exist.
  • You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

The attach task does nothing. No output; no breakpoints. I thought it might be because the open vsx extension bundles netcoredbg rather than vsdbg, but probably I'm missing something. Weirdly, everything else is working. Omnisharp code completion is working. I can debug non-godot projects (i.e. regular dotnet console apps). I can play a project from the editor, and any GD.Print calls are shown in the editor output log, so it seems like godot has all the C# dependencies it needs.

@eazrael
Copy link

eazrael commented Mar 26, 2023

FWIW. rafaelgdp's solution worked for me. Just make sure you use the main godot exe and not the console version.

Spent a couple of hours on this. This extension and the version in raulsntos fork do not compile anymore due to multiple issues with dependencies.

@Eole211
Copy link

Eole211 commented Apr 11, 2023

@M1N1M3

The solution in this issue didn't work for me in vscodium and muhammad-sammy's extension (But my error was not the same as yours). So I tried installing VsCode and the official C# omnisharp extension and now it's working fine.

@M1N1M3
Copy link

M1N1M3 commented May 16, 2023

I was able to do some more investigation today and found the root cause is indeed with netcoredbg. In short, it needs an enhancement to be able to detect dlls and pdbs that are loaded in memory.
See Samsung/netcoredbg#91
GodotSharp currently uses
AssemblyLoadContext.LoadFromStream(Stream, Stream)
to load your projects dll and pdb. netcoredbg has not implemented debugging symbols that are loaded in this way, although there is an open merge request.

As others have mentioned, the workaround is to use the official C# vscode extension, or otherwise wait for a netcoredbg enhancement to be made.

@wrightwriter
Copy link

@rafaelgdp 's solution worked for me in current version of gd

@Perustaja
Copy link

Perustaja commented Oct 9, 2023

Works still with godot 4.1.2 stable. Just make sure the .vscode directory is in your game's directory and launch it with the standard .NET debugger.

@GarrickWinter
Copy link

GarrickWinter commented Oct 11, 2023

@definitelyokay You're a hero! Pasting those two files into my project Just Worked. That you so very much. I've been struggling for a few days to understand how to get debugging to work, and I've been despairing at the (possibly outdated) claims I've seen online that C# debugging or breakpoints aren't supported by Godot. Glad to find out those claims are not accurate at present.

For others, I'm running Godot 4.1.1 stable mono version, on Windows 10, and Visual Studio Code version 1.82.2, with up-to-date versions of both the godot-tools and C# Tools for Godot plugins. I hardcoded the path to the Godot executable instead of using the environment variable, but otherwise I pasted the files without making other changes, and it worked like a charm.

@jolexxa
Copy link

jolexxa commented Oct 12, 2023

@GarrickWinter glad it helped! If you're looking for more on VSCode setup stuff, you might find some of this helpful.

@shitwolfymakes
Copy link

Likewise, if you need to be able to debug immediately once the app starts, you can use the below launch.json file. Make sure you've setup a GODOT4 environment variable which points to Godot on your machine.

{
  "version": "0.2.0",
  "configurations": [
    // For these launch configurations to work, you need to setup a GODOT4
    // environment variable. On mac or linux, this can be done by adding
    // the following to your .zshrc, .bashrc, or .bash_profile file:
    // export GODOT4="/Applications/Godot.app/Contents/MacOS/Godot"
    {
      "name": "Play",
      "type": "coreclr",
      "request": "launch",
      "preLaunchTask": "build",
      "program": "${env:GODOT4}",
      "args": [],
      "cwd": "${workspaceFolder}",
      "stopAtEntry": false,
    }
  ]
}

And the tasks.json file to build before each launch:

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "command": "dotnet",
      "type": "process",
      "args": [
        "build"
      ],
      "problemMatcher": "$msCompile",
      "presentation": {
        "echo": true,
        "reveal": "silent",
        "focus": false,
        "panel": "shared",
        "showReuseMessage": true,
        "clear": false
      }
    }
  ]
}

If you need more, I keep the most up-to-date versions that I use for VSCode here.

I've done this on 4.2.1 in VSCode but I'm getting an error:
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
I haven't been able to find any documentation that covers how to generate a .csproj or .sln, only this which just says that I need to.

@geekley
Copy link

geekley commented Jan 29, 2024

how to generate a .csproj or .sln

@shitwolfymakes .NET/Mono version of Godot should already generate a .csproj for you as soon as you create your first C# script from Godot Editor.

@shitwolfymakes
Copy link

shitwolfymakes commented Jan 29, 2024

@shitwolfymakes .NET/Mono version of Godot should already generate a .csproj for you as soon as you create your first C# script from Godot Editor.

After deleting, detaching, and re-adding the script, that worked! It appears that it didn't auto-generate because I hadn't configured VSCode as the external editor before adding the script. Thanks for the help!

@guasam
Copy link

guasam commented May 8, 2024

In case of anyone looking for C# workaround for debugging using Visual Studio Code based on this useful plugin, here is a basic boilerplate project:

https://github.com/guasam/godot-vscode-project

@Novack
Copy link

Novack commented May 25, 2024

I was able to do some more investigation today and found the root cause is indeed with netcoredbg. In short, it needs an enhancement to be able to detect dlls and pdbs that are loaded in memory. See Samsung/netcoredbg#91 GodotSharp currently uses AssemblyLoadContext.LoadFromStream(Stream, Stream) to load your projects dll and pdb. netcoredbg has not implemented debugging symbols that are loaded in this way, although there is an open merge request.

As others have mentioned, the workaround is to use the official C# vscode extension, or otherwise wait for a netcoredbg enhancement to be made.

@M1N1M3 Hey, did you ever tried netcoredbg again? (the fix was introduced).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.