Configuring Visual Studio to access Linux Projects directly via SSH

This tutorial shows how to use the VisualGDB CMake Project System to develop projects physically located on Linux machines with Visual Studio and VisualGDB. Unlike the regular VisualGDB projects that require downloading sources and headers on the Windows side or using hard-to-maintain shared folders, directly accessed projects let Visual Studio edit the files on the Linux machine directly, always ensuring that you are working with the latest versions of the files.

Before you begin, install VisualGDB 5.3 or later.

  1. Start Visual Studio and open the VisualGDB Linux Project Wizard:01-prjname
  2. VisualGDB can only use direct SSH access for CMake-based projects, so select “Create a new project -> Use CMake” and ensure that the “Use the advanced CMake Project Subsystem” checkbox is checked:02-cmake
  3. On the next page select your Linux machine:03-target
  4. On the “Source code access” select “Access the sources directly over SSH” and click “Finish” to generate the project:04-direct
  5. Build the project via “Ctrl-Shift-B”:05-build
  6. Ensure you can debug the project by pressing “F5”:06-debug
  7. Check the Windows folder of the project. Note how it does not contain neither the sources nor the built binaries, only the solution file, the VisualGDB project file and IntelliSense cache:07-folder
  8. Hover the mouse over the source file tab in Visual Studio. Note the “vgdb-ssh://” syntax that is used for remote projects:08-url
  9. Right-click on the target in Solution Explorer and select “Open Terminal Here”:term
  10. We will now install the “zlib” library on the Linux machine and show how VisualGDB will automatically recognize it. Run the “sudo apt-get install zlib1g-dev” command in the SSH Console:zlib
  11. Once the installation succeeds, try including the <zlib.h> header. See how IntelliSense immediately picks it up with no need to resynchronize any directories: 10-zlibinc
  12. Try calling the zlibVersion() function from your code. See how the link fails due to a missing definition of the called function:11-ver
  13. Open property pages for the main target and add “z” to the Linked Libraries field:12-libz
  14. See how VisualGDB automatically edits the target_link_libraries() statement in CMakeLists.txt:13-edit
  15. Try debugging the target to ensure the function gets called properly:14-ver
  16. Try adding a new source file via Add->New Item and immediately removing it (select “Remove”, not “Delete” to keep in on the disk). Then save your project:15-addsource
  17. Now select “Add->Existing Item”:16-existing
  18. See how VisualGDB is browsing the remote filesystem on the Linux machine as if the files were located on Windows:17-browse
  19. Right-click on the project in Solution Explorer and select “VisualGDB Project Properties”:   20-vgdbprop
  20. The VisualGDB Project Properties window allows editing various VisualGDB-specific project properties (e.g. you can explicitly specify the cmake location or add “-DCMAKE_VAR_NAME=VALUE” arguments to modify your project configuration):21-cmakeprop
  21. The VisualGDB CMake projects are self-sufficient. You can always build them from the Linux machine by running CMake:console
  22. VisualGDB uses a highly optimized cache mechanism to avoid downloading the same files over and over again. It maintains cached copies of the relevant files under the CodeDB\<project>\VFSCache directory and periodically checks the relevant remote directory for changes. Unlike the regular projects that require downloading of the entire include and source directories beforehand, the directly accessed projects read the necessary files only when needed, resulting in better performance and less confusion. You can view the internal state of the remote FS cache via View->Clang IntelliSense Diagnostics Console->Remote FS:statusThe console shows the exact time spent on listing directories and fetching files from the Linux machine, so you can quickly check whether your network connection provides sufficient performance for the direct access mode.