官方支持从Windows上的Visual Studio在WSL2中远程调试.NET Core Linux应用

本文介绍了如何在安装了WSL 2扩展的Visual Studio 2019中直接调试运行在WSL2上的.NET Core控制台和Web应用程序。开发者可以在Windows上无缝切换应用的运行环境,源代码保留在Windows系统,而.NET Core运行于Linux/WSL 2环境,调试过程畅通无阻。同时,文章提到了SSL证书在Windows和Linux Kestrel之间的共享机制。
摘要由CSDN通过智能技术生成

I've blogged before about Developing on Docker with the new and improved Visual Studio Container Tools (and WSL2) and also Remote Debugging a .NET Core Linux app in WSL2 from Visual Studio on Windows.

我之前写过关于使用新的和改进的Visual Studio容器工具(和WSL2)在Docker上进行开发以及在Windows中从Visual Studio在WSL2中远程调试.NET Core Linux应用的博客

It's the second one that I'm talking about today. You can now run .NET Core console and web apps in WSL2 and debug them directly from Visual Studio 2019!

这是我今天要谈论的第二个。 您现在可以在WSL2中运行.NET Core控制台和Web应用程序并直接从Visual Studio 2019对其进行调试

What do you need?

你需要什么?

Here's the experience in Visual Studio 2019 when the extension is installed. It "just works" and it makes it super easy to switch between running on Windows (under IIS or the Kestrel web server or under Kestrel under your default Linux distribution.

这是安装扩展程序后在Visual Studio 2019中的体验。 它“工作正常”,并且可以非常轻松地在Windows(在IIS或Kestrel Web服务器下,或在默认Linux发行版下的Kestrel下)上运行之间切换。

WSL 2 in the Visual Studio Debugging Menu

Check this out, you can see that .NET Core, from the Linux/WSL 2 perspective, is loaded out of /usr/share/dotnet/shared but my source remains on my /mnt/d drive (my Windows D:) and debugging Just Works.

进行检查,从Linux / WSL 2的角度来看,.NET Core已从/ usr / share / dotnet / shared中加载,但是我的源仍然在我的/ mnt / d驱动器(我的Windows D :)上,并且调试Just Works。

image

You'll also notice that we are running on https://localhost:5001 and that localhost and ports from the Windows point of view maps to localhost and points (via a local tunnel that's transparent) to WSL 2.

您还会注意到,我们在https:// localhost:5001上运行,并且从Windows的角度来看,localhost和端口映射到localhost,并(通过透明的本地隧道)指向WSL 2。

How does the SSL cert work if WSL 2's Linux Kestrel web server is serving it?

如果WSL 2Linux Kestrel Web服务器正在提供服务,则SSL证书如何工作?

You can see that there's a symbolic link between my WSL ~/.aspnet folder and my local profile in Windows so that this app shares SSL certs and that the same cert is served with Kestrel on Windows and Kestrel on Linux.

您可以看到,我的WSL〜/ .aspnet文件夹与Windows中的本地配置文件之间存在符号链接,因此该应用程序共享SSL证书,并且Windows上的Kestrel和Linux上的Kestrel都提供了相同的证书。

scott@IRONHEART:~$ cd .aspnet
scott@IRONHEART:~/.aspnet$ ls
DataProtection-Keys https
scott@IRONHEART:~/.aspnet$ cd https/
scott@IRONHEART:~/.aspnet/https$ ls
hanselminutes.core.pfx
scott@IRONHEART:~/.aspnet/https$ ls -alogF
total 12
drwxr-xr-x 2 4096 Jun 23 17:02 ./
drwxr-xr-x 4 4096 Jun 23 17:02 ../
lrwxrwxrwx 1 71 Jun 23 17:02 hanselminutes.core.pfx
->
/mnt/c/Users/scott/AppData/Roaming/ASP.NET/Https/hanselminutes.core.pfx*
scott@IRONHEART:~/.aspnet/https$

I broke that line up with the symbolic link -> along 3 lines so it wouldn't wrap on this blog.

我将符号链接->分成3行,所以它不会包装在本博客上。

Now you can run and debug .NET Core apps on Windows and Linux using both VS Code and Visual Studio 2019! I'm using Visual Studio 2019's free Community Edition and it works great. This helps me save money as I've moved my Podcast site to Linux in Azure and it makes my local development better match my cloud reality. Give it a try!

现在您可以使用VS CodeVisual Studio 2019在Windows和Linux上运行和调试.NET Core应用程序! 我正在使用Visual Studio 2019的免费社区版,并且效果很好。 当我将Podcast网站移到Azure中Linux上时,这可以帮助我节省金钱,并且可以使我的本地开发更好地适应我的云现实。 试一试!

翻译自: https://www.hanselman.com/blog/official-support-for-remote-debugging-a-net-core-linux-app-in-wsl2-from-visual-studio-on-windows

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值