godotengine / godot-csharp-vscode

Debugger and utilities for working with Godot C# projects in VSCode
https://marketplace.visualstudio.com/items?itemName=neikeq.godot-csharp-vscode
MIT License
144 stars 21 forks source link

Support for Godot 4 + mono #43

Open nonunknown opened 2 years ago

nonunknown commented 2 years ago

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

raulsntos commented 2 years ago

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 commented 1 year ago

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

timshannon commented 1 year ago

@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 commented 1 year ago

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

timshannon commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

timshannon commented 1 year ago

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

Seikho commented 1 year ago

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

rafaelgdp commented 1 year ago

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 commented 1 year ago

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

alexaisok commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

{ "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 commented 1 year ago

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 commented 1 year ago

@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 commented 1 year ago

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 https://github.com/Samsung/netcoredbg/issues/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 commented 1 year ago

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

Perustaja commented 11 months ago

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 commented 11 months ago

@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 commented 11 months ago

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

shitwolfymakes commented 7 months ago

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 commented 7 months ago

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 commented 7 months ago

@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 commented 4 months ago

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 commented 3 months ago

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).