Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Improvements:
- Improve ergonomics of the test explorer UI by removing the project source directory, improving horizontal scrolling experience. [#4562](https://github.com/microsoft/vscode-cmake-tools/issues/4562) [@miss-programgamer](https://github.com/miss-programgamer)
- Auto-generate `docs/cmake-settings.md` from `package.json` via CI so documentation never drifts from actual settings. [#4007](https://github.com/microsoft/vscode-cmake-tools/issues/4007)
- Pass mandatory compiler arguments from `CMAKE_<LANG>_COMPILER` to cpptools so it can properly determine system include paths and built-in preprocessor macro definitions. Requires CMake 4.3 or newer. [#4627](https://github.com/microsoft/vscode-cmake-tools/pull/4627) [@cwalther](https://github.com/cwalther)
- Add support for a `vsInstanceVersion` vendor field in `CMakePresets.json` so Ninja configure presets can target a specific installed Visual Studio instance (by version) when bootstrapping the developer environment, instead of always using the latest. [#4698](https://github.com/microsoft/vscode-cmake-tools/issues/4698)

Bug Fixes:
- Fix running a single test from the inline Test CodeLens or the project outline building the default (or all) target instead of the test's own executable; single-test runs now build only that test's target.
Expand Down
25 changes: 24 additions & 1 deletion src/presets/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,10 @@ export type OsName = "Windows" | "Linux" | "macOS";

export type VendorVsSettings = {
'microsoft.com/VisualStudioSettings/CMake/1.0': {
hostOS: OsName | OsName[];
hostOS?: OsName | OsName[];
intelliSenseMode?: string;
sourceDir?: string;
vsInstanceVersion?: number;
[key: string]: any;
};
[key: string]: any;
Expand Down Expand Up @@ -906,6 +909,20 @@ async function getVsDevEnv(opts: VsDevEnvOptions): Promise<EnvironmentWithNull |
}
}

// If VS instance wasn't chosen using CMAKE_GENERATOR_INSTANCE, check the vendor field
// for a preferred VS major version (e.g., 17 for VS2022, 18 for VS2026).
// This allows users to pin a specific VS version for the dev environment in Ninja presets.
let vendorVsVersion: number | undefined;
if (!vsInstall) {
const vendorSettings = (opts.preset.vendor as VendorVsSettings)?.['microsoft.com/VisualStudioSettings/CMake/1.0'];
if (vendorSettings?.vsInstanceVersion) {
vendorVsVersion = vendorSettings.vsInstanceVersion;
log.info(localize('using.vendor.vs.version',
"Configure preset {0}: Using Visual Studio major version {1} from vendor settings.",
opts.preset.name, vendorVsVersion));
}
}

// If VS instance wasn't chosen using CMAKE_GENERATOR_INSTANCE, look up a matching instance
// that supports the specified toolset.
if (!vsInstall) {
Expand All @@ -931,6 +948,12 @@ async function getVsDevEnv(opts: VsDevEnvOptions): Promise<EnvironmentWithNull |
vsInstall = vs;
break;
}
} else if (vendorVsVersion) {
// If a VS major version is specified via vendor settings, match against it.
if (vs.installationVersion.startsWith(vendorVsVersion.toString())) {
vsInstall = vs;
break;
}
} else if (!vsGeneratorVersion || vs.installationVersion.startsWith(vsGeneratorVersion.toString())) {
// If no toolset version specified then choose the latest VS instance for the given generator
vsInstall = vs;
Expand Down
Loading