January 24th, 2020

CMake, Linux targeting, and IntelliSense improvements in Visual Studio 2019 version 16.5 Preview 2

Erika Sweet
Senior Product Manager

Visual Studio’s native support for CMake allows you to target both Windows and Linux from the comfort of a single IDE. Visual Studio 2019 version 16.5 Preview 2 introduces several new features specific to cross-platform development, including:

File copy optimizations for CMake projects targeting a remote Linux system

Visual Studio automatically copies source files from your local Windows machine to your remote Linux system when building and debugging on Linux. In Visual Studio 2019 version 16.5 this behavior has been optimized. Visual Studio now keeps a “fingerprint file” of the last set of sources copied remotely and optimizes behavior based on the number of files that have changed.

  1. If no changes are identified, then no copy occurs.
  2. If only a few files have changed, then sftp is used to copy the files individually.
  3. If only a few directories have changed, then a non-recursive rsync command is issued to copy those directories.
  4. Otherwise, a rsync recursive copy is called from the first common parent directory of the changed files.

These improvements were tested against LLVM. A trivial change was made to a source file, which causes the remote source file copy to be called and the executable to be rebuilt when the user starts debugging.

Debugging LLVM-objdump with no optimizations Debugging LLVM-objdump with 16.5 optimizations 
Time elapsed for remote source file copy 3 minutes and 24 seconds 2 seconds

With no optimizations, a full recursive rsync copy is executed from the CMake root. With these optimizations, Visual Studio detects that a single file has changed and uses sftp to re-copy only the file that has changed.

These optimizations are enabled by default. The following new options can be added to CMakeSettings.json to customize file copy behavior.

“remoteCopyOptimizations” : {

“remoteCopyUseOptmizations”: “RsyncAndSftp”

“rsyncSingleDirectoryCommandArgs”: “-t”

}

Possible values for remoteCopyOptimizations are RsyncAndSftp (default), RsyncOnly, and None (where a full recursive rsync copy is always executed from the CMake root). rsyncSingleDirectoryCommandArgs can be passed to customize rsync behavior when a non-recursive rsync command is issued (step 3 above). The existing properties remoteCopySources, rsyncCommandArgs (which are passed when a recursive rsync command is issued, step 4 above) and rsyncCopySourcesMethod can also be used to customize file copy behavior. Please see Additional settings for CMake Linux projects for more information.

Note that these performance improvements are specific to remote connections. Visual Studio’s native support for WSL can access files stored in the Windows filesystem, which eliminates the need to copy and maintain sources on a remote machine.

Native WSL support with the separation of build and deploy

Visual Studio 2019 version 16.1 introduced the ability to separate your remote build system from your remote deploy system. In Visual Studio 2019 version 16.5 this functionality has been extended to include our native support for WSL. Now, you can build natively on WSL and deploy/debug on a second remote Linux system connected over SSH.

Separation of build and deploy with CMake projects

The Linux system specified in the CMake Settings Editor is used for build. To build natively on WSL, navigate to the CMake Settings Editor (Configuration drop-down > Manage Configurations…) and add a new WSL configuration. You can select either WSL-GCC-Debug or WSL-Clang-Debug depending on which toolset you would like to use.

The remote Linux system specified in launch.vs.json is used for debugging. To debug on a second remote Linux system, add a new remote Linux configuration to launch.vs.json (right-click on the root CMakeLists.txt in the Solution Explorer > Debug and Launch Settings) and select C/C++ Attach for Linux (gdb). Please see launch.vs.json reference for remote Linux projects to learn more about customizing this configuration and properties specific to the separation of build and deploy.

Note that the C/C++ Attach for Linux (gdb) configuration is for debugging on remote Linux systems. If you want to build and debug on the same instance of WSL, add a C/C++ Launch for WSL configuration to launch.vs.json. More information on the entry points to launch.vs.json can be found here.

Separation of build and deploy with MSBuild-based Linux projects

The Linux system specified in the Linux Property Pages is used for build. To build natively on WSL, navigate to Configuration Properties > General and set the Platform Toolset. You can select either GCC for Windows Subsystem for Linux or Clang for Windows Subsystem for Linux depending on which toolset you would like to use. Click “Apply.”

By default, Visual Studio builds and debugs in WSL. To specify a second remote system for debugging, navigate to Configuration Properties > Debugging and set Remote Debug Machine to one of the specified remote connections. You can add a new remote connection via the Connection Manager. You can also specify a path to the directory on the remote system for the project to deploy to via Remote Deploy Directory.

Easily add, remove, and rename files in CMake projects

It’s easier than ever to work with CMake projects in Visual Studio. In the latest preview, you can add, remove, and rename source files and targets in your CMake projects from the IDE without manually editing your CMake scripts. When you add or remove files with the Solution Explorer, Visual Studio will automatically edit your CMake project. You can also add, remove, and rename the project’s targets from the Solution Explorer’s targets view.

You can now easily add, remove, and rename files in CMake projects in Visual Studio

In some cases, there may be more than one place where it makes sense to add a source file to a CMake script. When this happens, Visual Studio will ask you where you want to make the change and display a preview of the proposed modifications:

Visual Studio will prompt you to resolve ambiguity when adding a new file to your CMake project

This feature is enabled by default as of Visual Studio 2019 15.5 Preview 2, but it can be turned off in Tools > Options > CMake, “Enable automatic CMake script modification…”

CMake language services

The latest Visual Studio preview also makes it easy to make sense of complex CMake projects. Code navigation features such as Go To Definition and Find All References are now supported for variables, functions, and targets in CMake script files.

CMake language services, including Peek Definition, in CMakeLists.txt

These navigation features work across your entire CMake project to offer more productivity than naïve text search across files and folders, and are integrated with other IDE productivity features such as Peek Definition. Stay tuned for more information on both CMake features in standalone blog posts coming soon.

Command line utility to interact with the Connection Manager

In Visual Studio 2019 version 16.5 or later you can use a command line utility to programmatically add and remove remote connections from the connection store. This is useful for tasks such as provisioning a new development machine or setting up Visual Studio in continuous integration. Full documentation on the utility including usage, commands, and options can be found here.

FIPS 140-2 compliance for remote C++ development

Federal Information Processing Standard (FIPS) Publication 140-2 is a U.S. government standard for cryptographic models. Implementations of the standard are validated by NIST. Starting with Visual Studio version 16.5 remote Linux development with C++ is FIPS 140-2 compliant. You can follow our step-by-step instructions to set up a secure, FIPS-compliant connection between Visual Studio and your remote Linux system.

IntelliSense improvements 

IntelliSense now displays more readable type names when dealing with the Standard Library. For example, in the Quick Info tooltip std::_vector_iterator<int> becomes_std::vector<int>::iterator.

We’ve also added the ability to toggle whether Enter, Space, and Tab function as commit characters, and to toggle whether Tab is used to Insert Snippet. Whether using a CMake or MSBuild project, you can find these settings under Tools > Options > Text Editor > C/C++ > Advanced > IntelliSense.

New Tools > Options > Text Editor > C/C++ > Advanced > IntelliSense settings in Visual Studio

Give us your feedback

Download Visual Studio 2019 version 16.5 Preview 2 today and give it a try. We’d love to hear from you to help us prioritize and build the right features for you. We can be reached via the comments below, Developer Community, email (visualcpp@microsoft.com), and Twitter (@VisualC). The best way to file a bug or suggest a feature is via Developer Community.

Author

Erika Sweet
Senior Product Manager

Erika works on the Visual C++ Team at Microsoft. She likes math and mystery novels. She is currently working on developer tools to support C++ cross-platform development.

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • Toni M

    How would you go about building and debugging a Makefile-based project in WSL?
    The normal Linux console project offers that nice WSL Platform Toolset you mentioned but wants to compile things by itself.
    The Linux Makefile project OTOH is geared towards remote systems.
    Bonus: what if the compiler is Linux mingw?

    • Erika SweetMicrosoft employee Author

      Hey Toni,

      Thanks for reaching out. Right now, we don’t have native support for WSL with out Makefile projects in Visual Studio. There is an existing feature suggestion on Developer Community that you can upvote & follow for updates here.