Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions OutOfProcessExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,7 @@ public static List<CompileCommand> ExtractCompileCommandsFromSolution(
string msbuildPath, string solutionPath, string configuration = "Debug",
string platform = "x64", bool enableLogger = false,
string? vcToolsInstallDir = null, string? vcTargetsPath = null,
string? clPath = null,
IReadOnlyDictionary<string, string>? msbuildProperties = null,
IReadOnlyDictionary<string, string>? msbuildEnv = null,
MsBuildLauncher launcher = MsBuildLauncher.Auto,
Expand All @@ -1138,6 +1139,7 @@ public static List<CompileCommand> ExtractCompileCommandsFromSolution(
var extractor = new OutOfProcessExtractor(
msbuildPath, project.Path, configuration, platform, enableLogger,
solutionDir, vcToolsInstallDir, vcTargetsPath,
clPath,
msbuildProperties: msbuildProperties,
msbuildEnv: msbuildEnv,
launcher: launcher,
Expand All @@ -1158,9 +1160,9 @@ public static List<CompileCommand> ExtractCompileCommandsFromSolution(
public static void WriteCompileCommandsJsonFromSolution(
string msbuildPath, string solutionPath, string configuration = "Debug",
string platform = "x64", bool enableLogger = false, string? outputPath = null,
string? vcToolsInstallDir = null, string? vcTargetsPath = null)
string? vcToolsInstallDir = null, string? vcTargetsPath = null, string? clPath = null)
{
var commands = ExtractCompileCommandsFromSolution(msbuildPath, solutionPath, configuration, platform, enableLogger, vcToolsInstallDir, vcTargetsPath);
var commands = ExtractCompileCommandsFromSolution(msbuildPath, solutionPath, configuration, platform, enableLogger, vcToolsInstallDir, vcTargetsPath, clPath);
outputPath ??= Path.Combine(Path.GetDirectoryName(Path.GetFullPath(solutionPath))!, "compile_commands.json");

var json = JsonSerializer.Serialize(commands, new JsonSerializerOptions
Expand Down
2 changes: 2 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ static List<CompileCommand> ExtractOutOfProcess(CommandLineOptions options)
return OutOfProcessExtractor.ExtractCompileCommandsFromSolution(
options.MsBuildPath!, options.Solution, options.Configuration, options.Platform,
options.EnableLogger, options.VcToolsInstallDir, options.VcTargetsPath,
clPath: options.ClPath,
emitDefaults: options.EmitDefaults, mergeDefaults: options.MergeDefaults);
}
else
Expand Down Expand Up @@ -362,6 +363,7 @@ static List<CompileCommand> ExtractMultipleInputs(CommandLineOptions options)
commands = OutOfProcessExtractor.ExtractCompileCommandsFromSolution(
options.MsBuildPath!, sln, options.Configuration, options.Platform,
options.EnableLogger, options.VcToolsInstallDir, options.VcTargetsPath,
clPath: options.ClPath,
msbuildProperties: options.MsBuildProperties,
msbuildEnv: options.MsBuildEnv,
launcher: ParseLauncher(options.MsBuildLauncher),
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ msbuild-extractor-sample --solution myapp.sln --format rich -o compile_database.
msbuild-extractor-sample --solution myapp.sln --msbuild-path "C:\VS\MSBuild\Current\Bin\MSBuild.exe" -c Debug -a x64
```

### Pin a specific toolchain (custom MSBuild, VC targets, and cl.exe)

Useful when the build uses a non-Visual-Studio toolchain (e.g. a package-based
MSBuild/MSVC) and you want `compile_commands.json` to reference that exact compiler
instead of an auto-detected Visual Studio install. `--cl-path` is honored for both
`--project` and `--solution` inputs.

```bash
msbuild-extractor-sample --solution myapp.sln -c Debug -a x64 \
--msbuild-path "C:\path\to\MSBuild\Current\Bin\amd64\MSBuild.exe" \
--vc-targets-path "C:\path\to\MSBuild\Extensions\Microsoft\VC\v170\" \
--cl-path "C:\path\to\VisualCppTools\lib\native\bin\cl.exe"
```

## Features

- **Zero-config extraction** - auto-detects Visual Studio via `vswhere.exe`, resolves `VCTargetsPath`, `VCToolsInstallDir`, and real `cl.exe` path automatically
Expand Down Expand Up @@ -129,6 +143,7 @@ Options:
--list-instances List all Visual Studio installations and exit
--vc-targets-path <path> VC targets directory (auto-detected)
--vc-tools-install-dir <path> VCToolsInstallDir property (auto-detected)
--cl-path <path> cl.exe path (overrides the resolved compiler; honored for --project and --solution)
--msbuild-path <path> MSBuild.exe path (enables out-of-process mode)
--use-dev-env Read Developer Command Prompt environment variables
--c-cpp-properties Emit .vscode/c_cpp_properties.json alongside the output
Expand Down
Loading