Using VS2019 with WSL (Windows Subsystem for Linux)

John Emmas 161 Reputation points
2020-08-20T15:48:35.387+00:00

Hi there - I tried to post a question about Visual Studio and got redirected here (so hopefully it's the right place !! )

I'm trying to install WSL which is a new-ish technology for allowing Visual Studio to build Linux apps. I followed these instructions

for installing WSL2 and Debian Linux - and I then ran the stated bash command - sudo apt install g++ gdb make rsync zip. Everything seemed to install okay and Debian itself is running fine - but it hasn't made any difference when I launch VS2019.

VS2019 stubbornly refuses to compile for Linux (I've tried both CMake and MS-Build).

I've checked and double-checked and triple-checkde and I'm pretty sure I've followed the instructions correctly. However... I'm only using the Community Edition of rVS2019. Is this maybe something which only works in the paid-for versions ?

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,869 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,628 questions
0 comments No comments
{count} vote

Accepted answer
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2020-08-21T10:21:33.987+00:00

    Hi JohnEmmas-0498,

    I follow this instructions with visual studio community 2019 and Debian. There are also some compilation errors on my side, maybe you could try these steps which can work for me:

    Cmake project:

    • Install Ninja on debian, the command: apt-get install ninja-build

    Linux console application:

    • In the project property page, select GCC for Windows Subsystem for Linux instead of GCC for Remote Linux
      19369-annotation-2020-08-21-181438.jpg

    After that, the application can compile and debug normally.

    19427-annotation-2020-08-21-1725716.jpg

    19428-annotation-2020-08-21-175716.jpg

    If these steps doesn't work, could you please provide some details about your compilation error?

    [Update]

    The configuration of msbuild project is different from cmake.

    From first document, you don't need to add connection in Connection Manager. You just need to right-click project in solution explorer, then switch the platform Toolset to GCC for Windows Subsystem for Linux.

    And according to your latest updates, you could follow this document:Configure a Linux MSBuild C++ project in Visual Studio to configure your linux msbuild project, and then build, debug, run it on remote linux system.

    I'm using the name and port number shown in the instructions and I've tried various different user names and passwords.

    You can try to use ip address instead of 'localhost'.

    [Edit...] A bit more info... I can't claim to understand this but I found a command online:- ssh -L1234:localhost:22 localhost and if I issue it from bash it gives me this error:- ssh: connect to host localhost port 22: Connection refused

    You can run these commands in linux system, which will enable ssh feature:

    sudo apt-get install openssh-client  
    sudo apt-get install nano  
    sudo service ssh restart  
    sudo service ssh status  
    ssh localhost  
    

    Now I just need to figure out where it puts the built files...

    You could check this directory in property page.
    sadasdadadasda

    Update:

    Intellisense is the only thing I still need to set up (for the Linux compilers). I did read something about it somewhere so I'll just need to find it again....

    Maybe this document is what you find: Improvements to Accuracy and Performance of Linux IntelliSense

    It doesn't seem possible yet to switch between the two platforms in just a single project.

    Yes, the linux project just works in linux system. If you want to remote debug normal msbuild project in remote windows system, you could read Remote Debugging a C++ Project in Visual Studio

    Best Regards,
    Dylan

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. John Emmas 161 Reputation points
    2020-08-27T12:57:31.753+00:00

    DylanZhu-MSFT wrote:
    You could open it in Debug Menu.

    Aaargh! I'd been looking under Debug->Windows

    Thanks again for all your help. It seems to be working fine now!