ms2cc creates a
compile_commands.json
file for C and C++ projects built with Visual Studio and MSBuild.
Tools such as clangd and clang-tidy use this file to find your source files and understand the same include paths, preprocessor definitions, and compiler options used by your build.
- Windows
- Visual Studio 2022 or Build Tools 2022, version 17.8 or newer
- The Desktop development with C++ workload
- Any packages and generated files required by your project
Run ms2cc from a command prompt where your project already builds correctly.
If your repository provides a setup script, run that script first.
Download the Windows executable from the releases page, or build it from source:
cargo build --releaseThe executable is written to target\release\ms2cc.exe.
Place ms2cc.exe in a directory listed in PATH, or invoke it using its full
path.
Open a Visual Studio Developer Command Prompt, change to your repository, and
pass ms2cc your solution or project:
cd C:\path\to\repository
ms2cc .\Project.slnThis creates compile_commands.json in the current directory.
For a large repository with a top-level .proj file, pass only that file.
ms2cc follows project references automatically:
ms2cc .\Build.projYou do not need to list every project below it.
Configuration and platform are optional. ms2cc uses the values provided by
MSBuild and the project. If the solution has more than one possible choice and
no clear default, choose one explicitly:
ms2cc .\Project.sln --configuration Debug --platform x64Write the database somewhere else:
ms2cc .\Project.sln --output C:\work\compile_commands.jsonCombine independent solutions or projects into one database:
ms2cc .\Engine.sln .\Tools.sln --output .\compile_commands.jsonPass a property required by your build:
ms2cc .\Build.proj --property BuildFlavor=Production--property may be repeated.
Use a specific MSBuild installation:
ms2cc .\Project.sln `
--msbuild C:\BuildTools\MSBuild\Current\Bin\MSBuild.exeRun ms2cc --help to see every option.
Some repositories provide a script that configures package locations, tools, or
environment variables. Run ms2cc from the same command prompt after running
that script:
cd C:\path\to\repository
call setup-build-environment.cmd
ms2cc Project.slnms2cc does not require changes to your project files or build scripts.
ms2cc asks MSBuild for the C and C++ files in your project and the compiler
options for each file. It follows referenced projects, checks that every source
file has a compiler command, and then writes the database.
It reads the project settings without compiling object files, so a clean build is not required. Projects that use C++20 modules or header units may run MSVC's dependency scanner, but its temporary files are kept outside the project.
Each successful run replaces the output database with the complete set of
projects requested on the command line. If anything fails, ms2cc leaves the
existing database unchanged.
Most editors find compile_commands.json automatically when it is placed at the
workspace root. You can also point clangd to its directory:
clangd --compile-commands-dir=C:\path\to\workspace
For VS Code with the clangd extension:
{
"clangd.arguments": [
"--compile-commands-dir=${workspaceFolder}",
"--background-index"
]
}ms2cc keeps the compiler options reported by MSBuild, including precompiled
header settings. Current clangd versions understand most MSVC options and remove
output-only options themselves. Do not remove options from the database unless
clangd reports a specific problem.
See docs/CLANGD_USAGE.md for help with MSVC precompiled headers and clangd.
ms2cc accepts:
.slnand.slnxsolution files.vcxprojVisual C++ projects.projfiles that refer to other projects
Referenced projects are followed automatically, so one top-level file is normally enough.
No. ms2cc reads the project settings directly from MSBuild.
Packages, imported project files, and generated source files still need to
exist. Run any restore, setup, or source-generation steps required by your
repository before running ms2cc.
No. It reads project information through MSBuild and writes only the requested compilation database. For C++20 modules and header units, it may run MSVC's dependency scanner in a temporary directory, but it does not compile object files or link the project.
Not when MSBuild or your project already provides a clear default. Use
--configuration and --platform when you want a specific configuration or
when a solution has more than one possible choice.
Some projects use environment variables to locate compilers, packages, SDKs, or
generated files. Running the setup script gives ms2cc the same environment as
the normal build.
A successful run replaces it with a complete new database for every root passed on the command line. It is not merged with the old file.
If generation fails, the existing file is left unchanged.
No. ms2cc is specifically for Visual C++ projects evaluated by MSBuild. CMake
can generate compile_commands.json directly, while tools such as
Bear may be more appropriate for other build
systems.
ms2cc does not automatically load MSBuild.rsp or Directory.Build.rsp. Pass
any required property explicitly:
ms2cc .\Build.proj --property Name=ValueUse a Visual Studio Developer Command Prompt, or pass the path explicitly with
--msbuild.
Increase the timeout:
ms2cc .\Build.proj --timeout 1200The timeout is measured in seconds.
cargo fmt --check
cargo clippy --all-targets -- -D warnings
cargo testMIT. See LICENSE.