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

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

问题描述

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

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

Mono运行时实现了一个调试接口,该接口允许 调试器和IDE来调试托管代码.这就是所谓的软 调试器,MonoDevelop,Xamarin Studio和 Visual Studio(安装了适当的插件时)以及 命令行SDB客户端.

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提供了与调试器进行通信并创建您的API的API. 通过Mono.Debugger.Soft.dll程序集自己的调试UI.

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

下面的页面讨论了当前MonoVS调试器实现的一些问题,但对我来说都很好.

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

该页面还链接到MonoVS入门指南:

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

http://mono-project.com/GettingStartedWithMonoVS

其中包含MonoTools的下载链接:

Which contains a download link for MonoTools:

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

但是,下载链接现在重定向到:

However, the download link now redirects to:

http://xamarin.com/download/

我提供下载Xamarin Studio简化版的位置.单击定价"链接,我看到我至少需要Visual Studio支持的商务版,每年999美元.好吧,不,谢谢.

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:

开发环境:

  • Windows 7 64位
  • Visual Studio Pro 2013(如果效果更好,则可以使用2010)

目标环境:

  • Raspberry Pi
  • Raspbian Wheezy
  • Mono 3.2.8
  • 通过SSH运行控制台应用程序

推荐答案

这是一个非常老的问题,但是我终于找到了一种对在Raspberry Pi上运行的C#代码进行远程调试的好方法.我已经从Mono切换到.NET Core,现在可以使用Visual Studio调试在Pi上运行的代码,就像在开发机上运行一样简单.

This is a very old question, but 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 Pi almost as easy as when running on my development machine.

以下步骤已使用Windows 10版本1909,Visual Studio 2019版本16.4.3,Raspbian Buster Lite版本2020-02-13和Raspberry Pi 2模型B进行了测试.NET Core需要ARMv7 CPU,因此它不会在Raspberry Pi 1和Zero上运行.

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. 转到 https://dotnet.microsoft.com/download/dotnet-core,然后选择.NET Core 3.1(或更高版本).单击Linux ARM32运行时二进制文件的链接,然后复制显示在下一页上的直接链接. (不要右键单击ARM32链接并选择复制链接地址,因为如果下载该链接,则会得到一个网页.)
  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.)

  1. 打开与Pi的SSH会话,下载并安装二进制文件:

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

  1. 将以下行添加到~/.bashrc,注销并再次登录以激活:
  1. Add the following line to ~/.bashrc, logout and login again to activate:

export DOTNET_ROOT=/opt/dotnet

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

dotnet --info

  1. 在Visual Studio中创建一个.NET Core Console App.设置Target framework = .NET Core 3.1(或您下载到Pi的版本).确保项目→属性→构建→输出→高级→调试信息=可移植.
  1. Create a .NET Core Console App in Visual Studio. Set Target framework = .NET Core 3.1 (or the version you downloaded to the Pi). Make sure that Project → Properties → Build → Output → Advanced → Debugging information = Portable.

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

cd bin\Debug\netcoreapp3.1
pscp -pw <password> *.dll *.pdb *.runtimeconfig.json pi@192.168.0.xxx:/home/pi

  1. 打开与Pi的SSH会话并运行程序,或使用ssh从开发计算机启动它:

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

  1. 通过在Visual Studio中选择调试"→附加到进程"菜单项来附加到远程进程.选择Connection type = SSH,然后在Connection target文本框中,键入pi@192.168.0.xxx,然后按Enter.
  1. 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.

  1. 输入密码,然后单击连接"按钮.

  1. 单击选择"按钮.

  1. 选择Managed (.NET Core for Unix),然后单击确定"按钮.
  1. Select Managed (.NET Core for Unix) and click the OK button.

  1. 选择dotnet MyProgram.dll进程,然后单击附加"按钮.第一次连接可能要花费几分钟,但随后的连接要快得多.
  1. 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天全站免登陆