godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.12k stars 69 forks source link

DotNet Solution Initialize Debug Launch Profile #8856

Open MattHackk opened 8 months ago

MattHackk commented 8 months ago

Describe the project you are working on

A 3D tower defense game using C# as main language.

Describe the problem or limitation you are having in your project

Debugging with C# breakpoints in visual studio does not work out of the box with Godot, it requires some configuration that is not obvious and could be implemented easily.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Automatically generate launch settings to allow out-of-the-box Godot debug from Visual Studio, improving accessibility to Godot for dotnet developers.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

Visual studio creates a \Properties\launchSettings.json file to define how to run the solution. I propose we create this file when the solution file is created. Here is an example of the file:

Default:

{
  "profiles": {
    "<SolutionName>": {
      "commandName": "Project"
    },
  }
}

Suggested

{
  "profiles": {
    "Godot": {
      "commandName": "Executable",
      "executablePath": "<PathToGodotExe>\\Godot_v4.1.2-stable_mono_win64.exe",
      "commandLineArgs": "--path, --verbose",
      "workingDirectory": ".",
      "nativeDebugging": true
    }
  }
}

It seems this would be possible in modules/mono/editor/GodotTools/GodotTools.ProjectEditor/DotNetSolution.cs

This will make the run solution button and F5 key in Visual Studio run the Godot project, rather than the default error "A project with an output type of class library cannot be started directly"

If this enhancement will not be used often, can it be worked around with a few lines of script?

It is easy to configure these settings if the user knows that it's possible. Documentation could also fill this role but creating a JSON file and not requiring new users to read through Microsoft and Godot documentation would improve accessibility of the platform.

Is there a reason why this should be core and not an add-on in the asset library?

This enables breakpoints and use of Visual Studio debugging features for dotnet developers using Godot. Breakpoints in dotnet development are essential and allows developers the use of Visual Studio's functionality. Before I discovered the solution to this problem, I was considering giving up on Godot due to the lack of debugging capability in dotnet.

While this can be easily fixed by following the right tutorial, it is also a very simple change that will reduce the barriers to introduce developers to Godot.

Pizzaandy commented 8 months ago

Seeing as Visual Studio is listed as an option in Project Settings, it feels right to have Godot handle this by default. It would be very nice to update the command line args from the Godot editor and have them automatically updated in the launch profile! I wonder if it would be feasible to have the Godot editor launch the game with VS debugging by default? Or maybe it makes more sense to push all this into a VS extension + package like Unity does.

lewiji commented 7 months ago

I think VS extension is the right move here - if it doesn't exist already. Not everyone uses VS - I use Rider, and there, the Godot Support plugin automatically creates the launch profiles in a C# godot project (and Rider uses a different format to store launch profiles).

raulsntos commented 7 months ago

I agree with lewiji. I think this should be done at the Visual Studio extension level. Unfortunately our official extension is unmaintained at the moment, but I'd like to change that.

van800 commented 2 weeks ago

jfyi, Rider supports both own format and launchSettings.json.