从 Visual Studio 进行 Linux .NET 远程调试 [英] Linux .NET remote debugging from Visual Studio

查看:23
本文介绍了从 Visual Studio 进行 Linux .NET 远程调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I would like to remote debug a C# console application running on Linux from Visual Studio. Here's what I found so far:

http://www.mono-project.com/Debugger

The Mono runtime implements a debugging interface that allows debuggers and IDEs to debug managed code. This is called the Soft Debugger and is supported by both MonoDevelop, Xamarin Studio and Visual Studio (when the appropriate plugins are installed) as well as the command line SDB client.

Mono provides an API to communicate with the debugger and create your own debugging UIs via the Mono.Debugger.Soft.dll assembly.

The page below discusses some issues of the current MonoVS debugger implementation, but they are all fine with me.

http://mono-project.com/Visual_Studio_Integration

The page also links to the Getting started guide for MonoVS:

http://mono-project.com/GettingStartedWithMonoVS

Which contains a download link for MonoTools:

http://mono-tools.com/download/

However, the download link now redirects to:

http://xamarin.com/download/

Where I'm offered to download Xamarin Studio Starter Edition. Clicking the Pricing link I see that I need at least the Business edition for Visual Studio Support, at $999 per year. Well, no thank you.

This is where I'm stuck. Some specifics of my environment:

Development environment:

  • Windows 7 64-bit
  • Visual Studio Pro 2013 (might use 2010 if that works better)

Target environment:

  • Raspberry Pi
  • Raspbian Wheezy
  • Mono 3.2.8
  • Running console application over SSH

解决方案

I have finally found a good way to perform remote debugging of C# code running on my Raspberry Pi. I have switched from Mono to .NET Core and can now use Visual Studio to debug code running on the Raspberry Pi almost as easy as when running on my development machine.

The following steps were tested using Windows 10 version 1909, Visual Studio 2019 version 16.4.3, Raspbian Buster Lite version 2020-02-13 and a Raspberry Pi 2 Model B. .NET Core requires an ARMv7 CPU, so it will not run on Raspberry Pi 1 and Zero.

  1. Go to https://dotnet.microsoft.com/download/dotnet-core and select .NET Core 3.1 (or later). Click the link for Linux ARM32 runtime binaries and copy the direct link displayed on the next page. (Do not right-click the ARM32 link and select copy link address, as you will end up with a webpage if you download that link.)

  2. Open a SSH session to the Raspberry Pi, download and install the binaries:

    ssh pi@192.168.0.xxx
    wget https://download.visualstudio.microsoft.com/download/pr/c11e9248-404f-4e5b-bd99-175079419d6f/83902a43e06f9fb4e45a4c6a6d5afc0b/dotnet-runtime-3.1.3-linux-arm.tar.gz
    sudo mkdir /opt/dotnet
    sudo tar zxf dotnet-runtime-3.1.3-linux-arm.tar.gz -C /opt/dotnet
    sudo ln -s /opt/dotnet/dotnet /usr/bin/dotnet
    

  3. Add the following line to ~/.bashrc, logout and login again to activate:

    export DOTNET_ROOT=/opt/dotnet
    

  4. Check that .NET Core has been installed correctly:

    dotnet --info
    

  5. Create a *.NET Core Console App```lang-none in Visual Studio. Set Target framework = .NET Core 3.1 (or the version you downloaded to the Raspberry Pi). Make sure that Project → Properties → Build → Output → Advanced → Debugging information = Portable.

  6. Build the project in Visual Studio and copy all *.dll, *.pdb, *.deps.json and *.runtimeconfig.json files from the development machine to the Pi. PuTTY's pscp command can be used:

    cd binDebug
    etcoreapp3.1
    pscp -pw <password> *.dll *.pdb *.deps.json *.runtimeconfig.json pi@192.168.0.xxx:/home/pi
    

  7. Open a SSH session to the Raspberry Pi and run the program, or start it from the development machine using SSH:

    ssh pi@192.168.0.xxx dotnet /home/pi/MyProgram.dll
    

  8. Attach to the remote process by selecting the Debug → Attach to Process menu item in Visual Studio. Select Connection type = SSH and in the Connection target textbox, type pi@192.168.0.xxx and press Enter.

  9. Enter password and click the Connect button.

  10. Click the Select button.

  11. Select Managed (.NET Core for Unix) and click the OK button.

  12. Select the dotnet MyProgram.dll process and click the Attach button. The first connection might take several minutes, but subsequent connections are much faster.

Enjoy setting breakpoints, adding watches, stepping through code and even using "Set Next Statement" - almost as fast as when debugging on the local machine. The only thing I'm missing so far is Edit and Continue, but not enough to investigate if it is possible to achieve.

这篇关于从 Visual Studio 进行 Linux .NET 远程调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆