Introducing source dependency reporting with MSVC in Visual Studio 2019 version 16.7

Cameron DaCamara

C++20 demands a lot more from the ecosystem than ever before. With C++20 Modules on the horizon the compiler needs to work closely with project systems in order to provide rich information for build dependency gathering and making iterative builds faster for inner-loop development. The compiler and project teams have acknowledged the new relationship and collaborated together to bring a new switch to the compiler toolset which can provide useful information to the build system: /sourceDependencies.

Source Dependency Reporting

The new switch for the compiler toolset enables the compiler to generate a source-level dependency report for any given translation unit it compiles. This report is output as a JSON file and you can produce it like this:

$ cl /Yupch.pch /FIpch.h /std:c++latest /experimental:module /module:reference m=m.ifc /headerUnit other.h=other.h.ifc /sourceDependencies main.json main.cpp

Notice the use of /sourceDependencies main.json.

Given the following program:

// main.cpp
#include "header.h"
import m;
import "other.h";

int main() { }

The dependency report generated to main.json might look something like:

    "Version": "1.0",
    "Data": {
        "Source": "C:\\...\\main.cpp",
        "PCH": "C:\\...\\pch.pch",
        "Includes": [
        "Modules": [

Additionally, the use of /sourceDependencies is not limited only to C++, it can also be used in translation units compiled as C! Moreover, the switch is designed to be used with multiple files and scenarios under /MP. Please see the documentation page for more information regarding these scenarios.

Stay Tuned

The /sourceDependencies output is subject to change and will evolve based on needs of the C++ build system ecosystem. The intent is to collect feedback from deployment in the field in order to provide feedback to the WG21/SG15 Study Group and to refine the proposal P1689. The documentation will be updated to reflect necessary future changes. We encourage users to leverage the Version field to account for the evolving nature, and to ensure that information contained in the dependency output are appropriately interpreted.

We urge you to go out and try using MSVC’s new /sourceDependencies switch. Visual Studio 2019 version 16.7 is available right now through the Visual Studio 2019 downloads page.

As always, we welcome your feedback. Feel free to send any comments through e-mail at or through Twitter @visualc. Also, feel free to follow me on Twitter @starfreakclone.

If you encounter other problems with MSVC in VS 2019 please let us know via the Report a Problem option, either from the installer or the Visual Studio IDE itself. For suggestions or bug reports, let us know through DevComm.