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

Does this extension allow debugging in cursor.sh for dotnet projects? #70

Open
dgokcin opened this issue May 30, 2024 · 7 comments
Open

Comments

@dgokcin
Copy link

dgokcin commented May 30, 2024

Hello

could you please describe/document how to get this debugger to work in cursor if it is still working with cursor? I tried bunch of different combinations but I am not able to get it to work. I would like to be able to debug a web api project and a console project either with dotnet 6 or 7 as close as possible to the debugging experience in vscode.

Here are the steps I followed:

  • On a clean IDE with no c# related extensions installed. I downloaded the latest version of this extension, extracted it and placed it under ${workspaceFolder}/netcoredbg.

  • Created a new project with dotnet new console. Added the following launch.json and tasks.json.

    .vscode/tasks.json
    {
      "version": "2.0.0",
      "tasks": [
        {
          "label": "build",
          "command": "dotnet",
          "type": "process",
          "args": [
            "build",
            "${workspaceFolder}/test.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
          ],
          "problemMatcher": "$msCompile"
        },
        {
          "label": "publish",
          "command": "dotnet",
          "type": "process",
          "args": [
            "publish",
            "${workspaceFolder}/test.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
          ],
          "problemMatcher": "$msCompile"
        },
        {
          "label": "watch",
          "command": "dotnet",
          "type": "process",
          "args": [
            "watch",
            "run",
            "${workspaceFolder}/test.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
          ],
          "problemMatcher": "$msCompile"
        }
      ]
    }
    .vscode/launch.json
    {
      "version": "0.2.0",
      "configurations": [
        {
          "name": ".NET Core Launch (console) with pipeline",
          "type": "coreclr",
          "request": "launch",
          "preLaunchTask": "build",
          "program": "${workspaceFolder}/bin/Debug/net6.0/test.dll",
          "args": [],
          "cwd": "${workspaceFolder}",
          "stopAtEntry": true,
          "console": "internalConsole",
          "internalConsoleOptions": "openOnSessionStart",
          "logging": {
            "diagnosticsLog": {
              "protocolMessages": true
            }
          }
          // tried with different versions of dotnet
          // tried with & without this pipe transport
          // tried building netcoredbg from source and using that
          // tried downloading the latest release of netcoredbg and using that
          // tried with the free c# extension and without it
          // "pipeTransport": {
          //     "pipeCwd": "${workspaceFolder}",
          //     "pipeProgram": "bash",
          //     "pipeArgs": ["-c"],
          //     // tried with different debuggers including this extension, samsung
          //     "debuggerPath": "${workspaceFolder}/netcoredbg/netcoredbg"
          //   },
        },
        {
          "name": ".NET Core Attach",
          "type": "coreclr",
          "request": "attach",
          "processId": "${command:pickProcess}"
        }
      ]
    }
  • Hit Debug(console)

I tried different combinations with the pipe transport, dotnet version etc. but the result is the same, debugger opens and closes and nothing happens in between or debugger hangs without hitting any of my breakpoints.

Note that this configurations works on vscode or vscode insiders with the official c# extension.

@cmerther
Copy link

Did you ever find a resolution to this? I'm running into the same issue.

@dgokcin
Copy link
Author

dgokcin commented Aug 14, 2024

@cmerther nope. I gave up after trying for a week. I felt like I was getting close but nothing I tried has worked.

@VoidMonk
Copy link

I got this extension to work in Cursor[1] (thanks to an unrelated video[2] and its referenced PR comment[3]).

These file configurations will allow debugging including hitting breakpoints:

launch.json (edit <net-runtime-folder> and <program-name> in pipeArgs below):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            "cwd": "${workspaceFolder}",
            "console": "internalConsole",
            "stopAtEntry": false,
            "logging": {
                "diagnosticsLog": {
                    "protocolMessages": true
                }
            },
            "internalConsoleOptions": "openOnSessionStart",
            "pipeTransport": {
                "pipeCwd": "${workspaceFolder}",
                "pipeProgram": "dotnet",
                "pipeArgs": [
                    "${workspaceFolder}/bin/Debug/<net-runtime-folder>/<program-name>.dll"
                ],
                "quoteArgs": true
            }
        },
        {
            "name": ".NET Attach",
            "type": "coreclr",
            "request": "attach",
        }
    ]
}

tasks.json (edit <program-name> in args below):

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "shell",
            "args": [
                "build",
                "${workspaceFolder}/<program-name>.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "group": "build",
            "presentation": {
                "reveal": "silent"
            },
            "problemMatcher": "$msCompile"
        }
    ]
}

Hope it helps.

[1] https://www.cursor.com
[2] https://www.youtube.com/watch?v=4XcvNMfe5PU
[3] #72 (comment)

@dgokcin
Copy link
Author

dgokcin commented Aug 25, 2024

were you able to hit the break point on a mac or on linux? @VoidMonk

@VoidMonk
Copy link

VoidMonk commented Aug 25, 2024

I tried on Windows and latest Cursor, and it hits breakpoints the first few times only, but this extension doesn't work reliably every time with Cursor. Not sure what/where the problem is.

As an alternative, I downloaded the netcoredbg[1] debugger that this extension uses, and tried it directly. That seems to work every time, by changing pipeTransport in launch.json as follows:

"pipeTransport": {
    "pipeCwd": "${workspaceFolder}",
    "pipeProgram": "cmd",
    "pipeArgs": [
        "/c",
    ],
    "debuggerPath": "<full-path-to-netcoredbg-executable",
    "debuggerArgs": [
        "--interpreter=vscode",
        "--",
    ],
    "quoteArgs": true
}

On a mac you can try replacing cmd with zsh (and remove the pipe arg). In Linux you can try replacing cmd with bash or similar shell (and replace the pipe arg accordingly).

So, I'm not sure what benefits this extension provides over just using netcoredbg directly. Maybe @muhammadsammy can clarify or help resolve this issue.

[1] https://github.com/Samsung/netcoredbg

@dgokcin
Copy link
Author

dgokcin commented Aug 27, 2024

@VoidMonk tried bunch of new things after my previous attempt, no luck I think this may be a Mac issue. would be really good if you can give https://github.com/dgokcin/dotnet-cursor-debugging-with-breakpoints a try and see if you can hit any of the breakpoints.

@muhammadsammy some confirmation about the usability of this extension on silicone macs would be really good.

@dgokcin
Copy link
Author

dgokcin commented Aug 29, 2024

@cmerther @VoidMonk I finally figured it out to make debugging work on my mac. for me the trick was to compile and install netcoredbg for my architecture and use the path of the built binary in the launch.json. I documented the steps needed in the repository below. Hope that it helps other people who come across to this!

https://github.com/dgokcin/dotnet-cursor-debugging-with-breakpoints/blob/main/README.md

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

No branches or pull requests

3 participants