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

[WIP] Godot4 Visual Studio 2022 Guide #48

Open
GeorgeS2019 opened this issue Mar 18, 2023 · 7 comments
Open

[WIP] Godot4 Visual Studio 2022 Guide #48

GeorgeS2019 opened this issue Mar 18, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request

Comments

@GeorgeS2019
Copy link

GeorgeS2019 commented Mar 18, 2023

Update March 2023

Firstly you need to create a new debugging profile Menu > Debug > Debug Properties

Selecting executable as a new profile type in the top corner of the profile configurator.

[Optional] Rename the executable profile

  • Enter the location of the Godot Executable and

    e.g. Godot_v4.0.1-rc2_mono_win64.exe

  • Enter the working directory to the project folder
Reference

Launch

in the command line
--path . --verbose

Launch (select scene)

in the command line
--path . scene.tscn --verbose

Launch (select Script)

in the command line
--path . --script <script> --verbose

Editor

in the command line
--path . --editor --verbose

Optionals

[1] Make GD.Print appear in the program output window (To be verified)

Include GD.cs ==> Need to update GD.cs to the lastest Godot4 rc2

Debugging Godot4 beta projects from VS and VSCode

I haven't found a fix for the first issue, but I've shared a GD.cs to pipe GD.Print functions to the output window. Just drop it into your project folder if you want that.

[2] Hot Reload (To be verified)

[3] Debug Editor Tool (To be verified)

If you want to also be able to debug editor tools add another profile and use the same arguments but add --editor as well.

--path . --editor
in the command line

Update Oct 2022

Debugging Godot4 beta projects from VS2022

Run+Debug Godot4 C# projects from Visual Studio

Debugging Godot4 beta projects from VS and VSCode

Is this Obsolete? VS2022 works with Godot 4.Beta1 no extension needed

@GeorgeS2019 GeorgeS2019 added the enhancement New feature or request label Mar 18, 2023
@GeorgeS2019 GeorgeS2019 changed the title [WIP] Godot4 Visual Studio Guide [WIP] Godot4 Visual Studio 2022 Guide Mar 18, 2023
@silenuz
Copy link

silenuz commented Mar 18, 2023

After entering the working directory you have to scroll down and check the box that says Enable native code debugging. This is missing from your instructions.

@GeorgeS2019
Copy link
Author

GeorgeS2019 commented Mar 18, 2023

@silenuz
I read through a few links, there are reasons WHEN and WHEN not to click => Enable Native code debugging.

@silenuz
Copy link

silenuz commented Mar 18, 2023

Without checking it you cannot debug unmanaged code. The Godot application itself is not managed code. And the process you are attaching the debugger to is the Godot exe and not the c# project. Thus for debugging to work you have to enable Native Debugging Mode.

"The following procedures describe how to enable debugging for managed and native code together, also known as mixed-mode debugging. There are two mixed-mode debugging scenarios:

The app that calls a DLL is written in native code, and the DLL is managed."

Mixed Mode Debugging

@GeorgeS2019
Copy link
Author

GeorgeS2019 commented Mar 18, 2023

@silenuz
Copy link

silenuz commented Mar 22, 2023

I would like to mention that a more universal approach than using . as the working directory, and path variables, is to use $(ProjectDir) which will allow the same profile to be used in Rider as well as Visual Studio.

For reference here is a complete launch file that should be compatible with VS, VS Code and Rider. All that has to be adjusted is the executable path for Godot. Note to use in VS code you would add this to your .vscode/launch.json file.

"launchSettingsProfile": "${workspaceFolder}/<Relative-Path-To-Project-Directory/Properties/launchSettings.json

For more information see: VS Code Debug

So the following file would go in a folder called properties in the project folder and be called launchsettings.json


{
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "Player": {
      "commandName": "Executable",
      "executablePath": "godot",
      "commandLineArgs": "--path $(ProjectDir)",
      "workingDirectory": "$(ProjectDir)",
      "nativeDebugging": true
    },
    "Editor": {
      "commandName": "Executable",
      "executablePath": "godot",
      "commandLineArgs": "--path $(ProjectDir) --editor",
      "workingDirectory": "$(ProjectDir)",
      "nativeDebugging": true
    }
  }
}

@silenuz
Copy link

silenuz commented Mar 24, 2023

If anyone cares I ended up creating a DotNet project template for Godot. Usage is simple:
dotnet new Godot -o {NameOfProject} -G {PathToGodtotExe}

This will create a project that already has the necessary launch settings for running or debugging your code in Visual Studio or Jetbrains' Rider. Note once installed the template will also be available in the above IDEs.

After the project is generated simply open it in the Godot editor as usual.

I'm currently working on packaging for easier use, and hope to have that finished by the end of the weekend.
Godot project Template

@UradaSources
Copy link

When selecting the executable file of godot, you cannot select the _console version, otherwise the breakpoint cannot be hit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants