0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

CursorでC#のデバッグをする方法

Posted at

CursorではC#のデバッグができない!

CursorでC#のコンソールアプリを書き、デバッグボタンを押したところ、以下のエラーが出力されました。
error-message-by-cursor.png

Unable to start debugging. .NET Debugging is supported only in Microsoft versions of VS Code. See https://aka.ms/VSCode-DotNet-DbgLicense for more information.

なんと、どうやらCursorでは.NETのデバッグができないらしい...。

この記事は、どうにかしてCursorでC#をデバッグ・実行できるようにするまでの記録です。

解決方法

結論から言うと、以下の記事を参考にすることで解決しました。

しかし自分の環境だと、他にも色々工夫しなければ上手くいかないことも多々あったので、備忘録も兼ねて自分が何をしたか共有します。

前提

前提として、VSCodeから移行するなどして、通常C#の実行に必要な拡張機能は入っているものとします。

また、自分の実行環境は以下の通りです。

  • Windows 11
  • Cursor 0.49.x
  • PowerShell 7.5.0

1. Samsungの.NET Core Runtimeデバッガーを導入する

どうやらあのSamsungが、.NET Coreのデバッガーをオープンソースで公開しているらしいです。
こちらを使用すればCursorでもデバッグ・実行が可能になる、という原理です。

Windowsの場合は、以下のURLから最新版のnetcoredbg-win64.zipをダウンロードし、任意の場所に解凍してください。
https://github.com/Samsung/netcoredbg/releases

2. .vscode/launch.jsonを編集する

以下のように設定しました。

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "netcoredbg",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "dotnet: build",
            "program": "${workspaceFolder}\\ConsoleApp1\\bin\\Debug\\net9.0\\ConsoleApp1.dll",
            "args": [],
            "cwd": "${workspaceFolder}",
            "pipeTransport": {
                "pipeCwd": "${workspaceFolder}",
                "pipeProgram": "powershell",
                "pipeArgs": ["-Command"],
                "debuggerPath": "C:\\netcoredbg\\netcoredbg.exe",
                "debuggerArgs": ["--interpreter=vscode"],
                "quoteArgs": true
            },
            "env": {
                "DOTNET_ENVIRONMENT": "Development"
            }
        }
    ]
}

サイトによって書いてある内容にバラツキがあるのですが、自分の環境では上記で上手くいきました。

以下注意点です。

  • preLaunchTaskにはbuildではなくdotnet: buildを指定する
    • .vscode/tasks.jsonを作成する必要もない
  • programには実行したいアプリケーションの.dllファイルを指定する
    • 通常はアプリケーション名.dllという形式になるはず
  • pipeTransport.debuggerPathには、手順1でダウンロードしたnetcoredbg.exeへのファイルパスを指定する
    • .exeは省略可

3. 実行する

左メニューのRun and Debugからnetcoredbgを選択して、実行します。

csharp-debug-works-in-cursor.png

無事に動きました!

まとめ

Cursorでも、Samsungのデバッガーを導入することでC#のデバッグができるようになります。
C#はWeb開発をはじめ、ゲーム制作やWindowsアプリケーション、モバイルアプリなど、様々なフレームワークで活用できる言語です。
CursorでC#を動かせるようになることで、AIアシストを活用しながらC#の開発・デバッグができるようになり、開発の幅が大きく広がります。
本当はMicrosoftがCursorでもC#のデバッグができるようにしてくれるのが一番ではありますが、しばらくはこの方法で制限を回避するのが良いでしょう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?