Recent versions of Visual Studio have included cross-platform support, notably for Android, iOS and now Linux. As Linux applications cannot (obviously) run natively on Windows, one can either
In this guide, we'll use the latter method as it's more 'native', though those wishing to use the former method can also use this guide.
Visual Studio 2019 can natively detect the presence of WSL. This means that while you still have to install WSL, you may not have to follow all of the other steps. |
You'll need
$ sudo apt update$ sudo apt install -y build-essential$ sudo apt install -y gdbserver$ sudo apt install -y openssh-server
/etc/ssh/sshd_config using a code editor; for example,sudo nano /etc/ssh/sshd_config. Look forPasswordAuthentication and set it toyes.$ sudo ssh-keygen -A$ sudo service ssh start
You need to have the Linux compiler installed on WSFL! Use appropriateapt-get commands as necessary to install them (eg:sudo apt-get g++). Otherwise, you'll get an error when trying to run (or after clicking Add in the previous step)
If you can't see any output, make sure that your program has at least one waiting state. This is because the Linux Console Window disappears, and its contents erased, when the program stops debugging (it has the same effect as debugging a normal Windows program through VS if you haven't configured it not to close immediately).
If you are programming in C, make sure to set the file extension as .c for IntelliSense to work. Even then, you may get errors saying that common header files like stdio.h cannot be found; this is a bug and the program should still compile. |
You can use it much like you'll debug a normal Windows program. The main exception is that features like CPU tracking are restricted, which is because the app is technically run elsewhere - on the Linux subsystem. One can easily set breakpoints, watch, locals and autos as normal. When (if?) a segmentation fault occurs, Visual Studio will halt the program and show the nearest location where the fault could have occurred (like what you'd get if you usedgdb and enabled debugging symbols).
It is often possible to customise debugging settings. To do so would be the same as it's done on Windows - by going to Project Settings.