Generate a Clang compile_commands.json from MSBuild — for C++ projects built
with Visual Studio solutions (.sln / .vcxproj) and the MSVC CL.exe
toolchain.
msbuild-compdb makes MSBuild-based C++ projects usable in editors and tooling
that rely on a compilation database — clangd, clang-tidy, and other
Clang-based tools — so you get code navigation, completion, and diagnostics
outside Visual Studio (for example in Neovim).
Language servers like clangd don't understand .sln / .vcxproj directly;
they work from a compile_commands.json. Visual Studio doesn't produce one.
msbuild-compdb bridges that gap by reconstructing the real CL.exe compile
commands from a build and emitting a standard compilation database.
- Two modes: parse an existing binary log (
.binlog), or build a solution/project and parse the result — both from a single executable. - Recovers the exact
CL.execommand line per source file. - Adds the system/SDK/vcpkg include directories (which
CLnormally takes from theINCLUDEenvironment variable) as clang-cl/imsvcflags, soclangdresolves standard and Windows headers even when launched outside a VS developer shell. - Emits one entry per source file, as the compilation database format expects.
- Recognizes
.cpp,.cc,.cxx,.c++, and.csources. - Ships as a single self-contained
.exe— no .NET runtime required on the target machine.
Grab the latest msbuild-compdb.exe from the
releases page and drop it
anywhere on your PATH (or bundle it with your editor plugin).
Requires the .NET SDK (8.0 or newer):
git clone https://github.com/max-wolf-cpp/msbuild-compdb.git
cd msbuild-compdb
dotnet publish MSBuildCompDb/MSBuildCompDb.csproj -c Release -o ./artifactsThe single-file executable is produced at ./artifacts/msbuild-compdb.exe.
msbuild-compdb --binlog <path.binlog> [--output compile_commands.json]
msbuild-compdb --build <path.sln|.vcxproj> [--output compile_commands.json] [-- <msbuild args>]
| Option | Description |
|---|---|
-i, --binlog |
Parse an existing MSBuild binary log. |
-b, --build |
Build the project/solution (msbuild /bl) and parse the result. |
-o, --output |
Output path (default: compile_commands.json). |
-h, --help |
Show help. |
Everything after -- is forwarded verbatim to MSBuild, e.g. to pick a
configuration:
msbuild-compdb --build MySolution.sln -- /p:Configuration=Debug /p:Platform=x64Build your project with binary logging enabled, then convert it:
msbuild MySolution.sln /bl:msbuild.binlog
msbuild-compdb --binlog msbuild.binlog --output compile_commands.jsonIf you'd rather not produce a binlog yourself, let the tool run the build (it
locates MSBuild via vswhere):
msbuild-compdb --build MySolution.sln --output compile_commands.json[
{
"directory": "E:/Projects/MyGame/Engine",
"command": "\"C:/.../CL.exe\" /c /I... /std:c++20 /imsvc \"C:/.../MSVC/.../include\" Source/Engine.cpp",
"file": "E:/Projects/MyGame/Engine/Source/Engine.cpp"
}
]The command keeps MSVC-style flags and CL.exe as the driver; clangd detects
this and switches to clang-cl mode, so /I, /D, /std:c++20, etc. are
understood as-is.
msbuild-compdb reads the binary log with
MSBuild.StructuredLogger,
then for every CL task:
- extracts the full
CL.execommand line from the task's messages; - determines the owning project's directory;
- splits out each source file into its own database entry;
- reads the project's
IncludePathproperty and appends the system include directories as/imsvcflags; - writes a standard
compile_commands.json.
Point clangd at the generated database (place it at your project root, or pass
--compile-commands-dir). In Neovim this works with nvim-lspconfig /
clangd, or with build-plugins that manage clangd for you.
Focused on Windows + MSBuild + Visual Studio C++ projects + CL.exe. It does
not aim to replace MSBuild, parse .sln/.vcxproj directly, or support
arbitrary compilers and build systems.
- Only compile commands present in the build (binlog) can be reconstructed.
- Windows / MSVC
CL.exeonly; other toolchains are out of scope. - Behavior depends on how MSBuild logged the compiler invocation; unusual or generated project layouts may need adjustments.
MIT © Max Wolf