简体   繁体   English

从Visual Studio 2017连接到Windows的Windows子系统

[英]Connecting to the Windows Subsystem for Linux from Visual Studio 2017

I wish to debug a Linux C++ console application from VS2017, as in these tutorials: 我希望从VS2017调试Linux C ++控制台应用程序,如以下教程:

Writing And Debugging Linux C Applications From Visual Studio Using The Windows Subsystem For Linux 使用适用于Linux的Windows子系统从Visual Studio编写和调试Linux C应用程序

targeting windows subsystem for Linux from visual studio 从visual studio定位Linux子系统

I have installed gdbserver and openssh-server in my WSL Ubuntu 16.04 installation, and sshd is running, but I cannot connect from VS2017. 我已经在我的WSL Ubuntu 16.04安装中安装了gdbserver和openssh-server,并且sshd正在运行,但我无法从VS2017连接。 When I try, I get the error 'Connectivity Failure. Please make sure the host name and port number are correct' 当我尝试时,我收到错误'Connectivity Failure. Please make sure the host name and port number are correct' 'Connectivity Failure. Please make sure the host name and port number are correct' . 'Connectivity Failure. Please make sure the host name and port number are correct'

Visual Studio 2017连接到Linux

Both the host name and port number are correct as far as I am concerned. 就我而言,主机名和端口号都是正确的。 I know that WSL is still Beta, so I am assuming the problem has something to do with WSL (I recently installed the Windows 10 Creators Update so it is at least up to date, but I was expecting ssh to work with CU). 我知道WSL仍然是Beta,所以我假设问题与WSL有关(我最近安装了Windows 10 Creators Update,所以它至少是最新的,但我期待ssh与CU一起工作)。 I'm using Windows 10 version 1703, Build 15063.250. 我正在使用Windows 10版本1703,Build 15063.250。

Update I got Visual Studio to connect to my Ubuntu VM, which proves that it works and the problem must be with Bash on Windows. 更新我让Visual Studio连接到我的Ubuntu VM,证明它可以工作,问题必须在Windows上使用Bash。 Nothing works with incoming connections, but outgoing connections work as expected. 传入连接没有任何作用,但传出连接按预期工作。

VS连接管理器对话框

Has anyone else had problems with connecting to WSL from Visual Studio 2017 in this way? 有没有其他人以这种方式从Visual Studio 2017连接到WSL有问题?

Yes, it looks like this issue has already been reported here and here . 是的,看起来这个问题已经在这里这里报道

According to a recent comment on the latter thread, the problem has been resolved in Windows Insider build 16199. Depending on your circumstances, this might be an option for you until such time as the fix is incorporated into the release version. 根据最近对后一个主题的评论,该问题已在Windows Insider内部版本16199中得到解决。根据您的具体情况,这可能是一个选项,直到修复程序合并到发行版本中。

If you are in a production environment, I recommend continuing to use the VM. 如果您在生产环境中,我建议继续使用VM。 I've not personally had too much trouble with Windows Insider builds, but there's always some risk involved. 我个人对Windows Insider版本没有太多麻烦,但总是存在一些风险。

I faced the same problem with windows build with 16299 and am able to resolve the issue now. 使用16299的Windows构建遇到了同样的问题,现在我可以解决这个问题了。 Posting the resolution in case it helps any other fellow programmer. 发布决议,以防它帮助任何其他程序员。 (Though James might have already resolved it) (虽然詹姆斯可能已经解决了它)

WSL lacks open ssh server by default. 默认情况下,WSL缺少开放的ssh服务器。 It has to be configured first for you to be able to connect with Visual Studio 必须首先配置它才能与Visual Studio连接

To double check this. 要仔细检查一下。 Go to Powershell and run netstat -an. 转到Powershell并运行netstat -an。 I was not able to find anything running on localhost::22. 我无法在localhost :: 22上找到任何运行的东西。

Follow these instructions to Install open ssh on WSL install and run open ssh server. 按照以下说明在WSL安装上安装open ssh并运行open ssh server。

In the output of nestat -an, now you should see something like below 在nestat -an的输出中,现在您应该看到类似下面的内容

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:22             0.0.0.0:0              LISTENING

Now, I am able to connect VS to WSL. 现在,我能够将VS连接到WSL。 :-) Cheers!! :-)干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当提示从 Visual Studio 2019 IDE 启动时,为什么 wsl(Linux 的 Windows 子系统)在命令提示符中不可用? - Why is wsl (windows subsystem for linux) not available in command prompt when prompt started from the Visual Studio 2019 IDE? Flutter 和 Windows Linux 的子系统 - Flutter and Windows Subsystem for Linux 从 WSL(Linux 的 Windows 子系统)写入 Windows 磁盘 - Write to windows disk from WSL (Windows subsystem for Linux) 如何从WSL(Linux的Windows子系统)访问aws配置文件? - How to access aws config file from WSL (Windows subsystem for Linux)? 从 Sublime Text 使用 Windows Subsystem for Linux (WSL) - Using Windows Subsystem for Linux (WSL) from Sublime Text 在适用于Linux的Windows子系统上安装Apache - Installing Apache on Windows Subsystem for Linux 是否存在适用于Linux的Windows子系统的便携式版本 - Is there a portable version of the Windows Subsystem for Linux 在带有 Linux 子系统的 Windows 上取消共享文件夹 - Unshare a folder on Windows with Linux subsystem 从Linux交叉编译到Windows Visual Studio项目 - Cross compile from linux to windows a visual studio project Visual Studio 2017跨平台中特定于Linux的标头 - Linux-Specific Headers in Visual Studio 2017 Cross-Platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM