如何从 Rider 调试 WSL2 中的进程?

Tim*_*ass 9 c# debugging rider wsl-2

我想调试在 WSL2 下运行的 .NET Core 进程,但无法从 Windows 中的 Rider 附加到它。有办法实现这一点吗?

Tim*_*ass 11

您可以将 WSL2 发行版视为远程计算机,并使用 Rider 的远程调试工具来实现此目的。这些说明基本上遵循此处记录的内容: https: //www.jetbrains.com/help/rider/SSH_Remote_Debugging.html#set-up-ssh-server-on-the-remote-machine

在您的 wsl2 控制台中:

$ # fetch the jetbrains debug agent
$ cd ~
$ wget -o jetbrains-debug-agent https://www.jetbrains.com/help/rider/SSH_Remote_Debugging.html#set-up-ssh-server-on-the-remote-machine
$ chmod +x jetbrains-debug-agent
$ ./jetbrains-debug-agent
Please, use these credentials to establish SSH connection
Login:  xxxxxxxx
Password:  xxxxxxxxxxxxxxx
Port:  1234

$ # then determine your local IP address
$ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.11.60  netmask 255.255.240.0  broadcast 192.168.15.255
...

$ # then, in Rider, choose Run > Attach To Remote Process
$ # it'll ask you to setup connection details for the remote machine
$ # it'll tell you that it needs to install remote debug components; you'll need to agree
$ # then attach ...
Run Code Online (Sandbox Code Playgroud)