Enhancing Your Workflow: Setting Up Visual Studio Code with Godot and .NET

Enhancing Your Workflow: Setting Up Visual Studio Code with Godot and .NET

As we continue our Godot journey, let's optimize our development environment by integrating Visual Studio Code with Godot and the .NET framework. This powerful combination unlocks advanced coding features and streamlines the game development process. In this guide, we'll walk through the steps to set up Visual Studio Code for a seamless Godot and .NET experience.

Why Visual Studio Code?

Visual Studio Code (VSCode) is a lightweight, open-source code editor that boasts robust features, extensions, and a vibrant community. When paired with Godot and .NET, it becomes a potent tool for efficient game development.

Setting Up Visual Studio Code with Godot and .NET

  1. Install Visual Studio Code:

    • If you haven't already, download and install Visual Studio Code from the official website.

    • Alternatively, use brew to install brew install --cask visual-studio-code

  2. Install the C# Extension:

    • Open VSCode and go to the Extensions view (Ctrl+Shift+X or Cmd+Shift+X on macOS).

    • Search for "C# Dev Kit" and install the one provided by Microsoft.

    • Search for “C# Tools for Godot” and install this extension as well.

  3. Open Your Godot Project:

    • Launch Godot and open your project.
  4. Generate Project Files:

    • In the Godot Editor, go to "Project" -> "Tools" -> “C#”

    • Click "Generate C# solution" to create the necessary project files for .NET.

  5. Configure Visual Studio Code:

    • Open your project folder in VSCode.

    • Open your Command Palette (Cmd+Shift+X on macOS) and execute C# Godot: Generate Assets for Build and Debug

    • This will create a new folder named .vscode in the root of your project.

    • Inside the .vscode folder, you will find two files **launch.json** and tasks.json

  6. Configure GODOT4 environment variable

  7. Configure launch.json:

    • Add the following configuration to launch.json:
    {
        "version": "2.0.0",
        "configurations": [
            {
                "name": "Launch",
                "type": "coreclr",
                "request": "launch",
                "preLaunchTask": "build",
                "program": "${env:GODOT4}",
                "cwd": "${workspaceFolder}",
                "console": "internalConsole",
                "stopAtEntry": false,
                "args": [
                    "--path",
                    "${workspaceRoot}"
                ]
            },
            {
                "name": "Launch (Select Scene)",
                "type": "coreclr",
                "request": "launch",
                "preLaunchTask": "build",
                "program": "${env:GODOT4}",
                "cwd": "${workspaceFolder}",
                "console": "internalConsole",
                "stopAtEntry": false,
                "args": [
                    "--path",
                    "${workspaceRoot}",
                    "${command:godot.csharp.getLaunchScene}"
                ]
            },
            {
                "name": "Launch Editor",
                "type": "coreclr",
                "request": "launch",
                "preLaunchTask": "build",
                "program": "${env:GODOT4}",
                "cwd": "${workspaceFolder}",
                "console": "internalConsole",
                "stopAtEntry": false,
                "args": [
                    "--path",
                    "${workspaceRoot}",
                    "--editor"
                ]
            },
            {
                "name": "Attach to Process",
                "type": "coreclr",
                "request": "attach"
            }
        ]
    }
  • Save the file.
  1. Configure tasks.json

    • Add the following configuration to your tasks.json:
    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "command": "dotnet",
                "type": "shell",
                "args": [
                    "build",
                    "/property:GenerateFullPaths=true",
                    "/consoleloggerparameters:NoSummary"
                ],
                "group": {
                    "kind": "build",
                    "isDefault": true
                },
                "presentation": {
                    "reveal": "silent"
                },
                "problemMatcher": "$msCompile"
            }
        ]
    }
  1. Reload Visual StudioCode

    • Reload Visual Studio Code to apply the changes.

Configuring Launch Options in Visual Studio Code

Fine-tune your Godot development experience with launch configurations in Visual Studio Code. These configurations mirror the convenience of Godot 4 Editor options, offering seamless execution and debugging for your projects.

Launch

Experience the Godot 4 Editor's Run Project (Cmd + B on macOS) seamlessly within Visual Studio Code. This configuration swiftly initiates your Godot project, utilizing the main/default scene without any editor clutter.

Launch (Select Scene)

Mirror the Godot 4 Editor's Run Specific Scene (Shift + Cmd + B on macOS) functionality. Engage a convenient popup window, empowering you to handpick a scene for execution, ensuring a focused run without editor distractions and clicking through scenes.

Launch Editor

Initiate the Godot 4 Editor directly from Visual Studio Code, launching your current Godot project within the dedicated editor environment.

Attach to Process

Unlock advanced debugging capabilities by seamlessly attaching a debugger to a running Godot 4 project. Debug with precision using Visual Studio Code for an enhanced development experience.

References

  1. Setup C# Godot 4 Build and Debugging in VS Code | Quick guide & DETAILED explanations by Jace Varlet

  2. Godot 4 VSCode C# build configs

Now, you have a fully configured Visual Studio Code environment for Godot and .NET development. Enjoy features like code completion, debugging, and seamless integration between your code editor and Godot. Stay tuned for more advanced Godot tutorials!

That concludes our setup guide. Happy coding!