Running Microsoft Edge on Linux with WSLg while running Visual Studio 2019 and debugging a Linux .NET app with WSL on Windows 10
How about that insane blog title?
You can do lots of cool things with WSLg, which allows you to seamlessly and cleanly run Linux apps on Windows. I've written about this before.
- Can you really develop with Linux GUI Apps on Windows 10 with WSLg? How about PyCharm?
- How to run Linux GUI apps on Windows 10 with WSL and WSLg
And you know that you've been able to run Linux server apps on Windows for a long time. There's even support in VS Code and VS2019 to debug those apps.
- Remote Debugging a .NET Core Linux app in WSL2 from Visual Studio on Windows
- Official Support for Remote Debugging a .NET Core Linux app in WSL2 from Visual Studio on Windows
But how far can we take this? What about Debugging a .NET web app running under Linux while running Visual Studio 2019 for Windows and accessing that web app via a Linux Browser?
Why? Why the heck not? Seriously though, because choice and flexibility. If this solution isn't interesting to you, then perhaps you don't have this problem. But if you do have this problem, then here's the solution. Welcome!
Prerequisites
At some point soon, WSL and WSLg will be a part of the mainline of Windows, but at the time of this writing they are inside Windows 10 Insiders 21362+. Follow the instructions here to setup WSL2 and WSLg. This assume you're running a distro like Ubuntu.
Then add a browser like Edge for Linux or Chrome for Linux as below.
## Google Chrome
cd /tmp
sudo wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
sudo apt install --fix-broken -y
sudo dpkg -i google-chrome-stable_current_amd64.deb
## Microsoft Edge Browser
sudo curl https://packages.microsoft.com/repos/edge/pool/main/m/microsoft-edge-dev/microsoft-edge-dev_91.0.852.0-1_amd64.deb -o /tmp/edge.deb
sudo apt install /tmp/edge.deb -y
You'll know they are working and installed when the Linux GUI apps show up in the Windows Start Menu.
Adding a Linux Browser to Windows Visual Studio 2019
Open up Visual Studio 2019, and either open up or create a Web Application. From Debug button there's a dropdown (chevron) where you access this menu:
Select "Browse With..."
From the Browse With dialog, you're going to add a new Browser, selecting "C:\Windows\System32\wslg.exe
" as the Program and "~ -d Ubuntu /usr/bin/microsoft-edge-dev
" as the Arguments. Ignore any errors.
You should see the new Browser inside Visual Studio 2019 now and can select it like any other browser.
Boom. Here I am running my Podcast website under Linux on .NET 5 on the server-side AND on the client-side in the Edge Browser as a Linux GUI app!
Enjoy! And please watch the BUILD 2021 Application Development Keynote, I think you'll enjoy it.
Sponsor: Build your apps where your customers are. Oracle for Startups delivers enterprise cloud with no lock-in so you can go after any customer—confidently. Learn more.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.
About Newsletter
Comments are closed.