来自 Visual Studio 的 Linux .NET 远程调试 [英] Linux .NET remote debugging from Visual Studio

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

问题描述

我想从 Visual Studio 远程调试在 Linux 上运行的 C# 控制台应用程序.这是我目前发现的:

  • 打开到 Raspberry Pi 的 SSH 会话,下载并安装二进制文件:

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

  • ~/.bashrc中加入下面一行,注销重新登录激活:

    export DOTNET_ROOT=/opt/dotnet

  • 检查 .NET Core 是否已正确安装:

    dotnet --info

  • 在 Visual Studio 中创建一个 *.NET Core 控制台应用程序```lang-none.设置 Target framework = .NET Core 3.1(或您下载到 Raspberry Pi 的版本).确保 Project → Properties → Build → Output → Advanced → Debugging information = Portable.

  • 在 Visual Studio 中构建项目并将所有 *.dll、*.pdb、*.deps.json 和 *.runtimeconfig.json 文件从开发机器复制到 Pi.可以使用PuTTY的pscp命令:

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

  • 打开与 Raspberry Pi 的 SSH 会话并运行程序,或使用

  • 输入密码并点击连接按钮.

  • 点击选择按钮.

  • 选择Managed (.NET Core for Unix)并点击确定按钮.

  • 选择 dotnet MyProgram.dll 进程并单击 Attach 按钮.第一次连接可能需要几分钟,但随后的连接速度要快得多.

  • 享受设置断点、添加监视、单步执行代码甚至使用设置下一个语句"的乐趣;- 几乎和在本地机器上调试时一样快.到目前为止,我唯一缺少的是编辑并继续,但还不足以调查是否有可能实现.

    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天全站免登陆