From 8ee397b7d70a83b45459574e2d194df2e8e9d149 Mon Sep 17 00:00:00 2001 From: CoreyShay <11512658+CoreyShay@users.noreply.github.com> Date: Mon, 24 Aug 2026 18:42:25 -0700 Subject: [PATCH] Support Visual Studio 2026 and write args to the active VC configuration Two changes are needed to make the extension usable in VS2026 (18.x): 1. Widen the VS2022 InstallationTarget from [17.0, 18.0) to [17.0, 19.0) so the VSIX can be installed at all, and widen the Microsoft.VisualStudio.Component.CoreEditor prerequisite to match. The prerequisite was capped at [17.0, 18.0) as well, which excludes the VS2026 core editor. 2. For C/C++ projects the arguments were written to the configuration returned by VCProject.ActiveConfiguration. In VS2026 that can be a different configuration than the one which is actually active, so the arguments were written to the wrong configuration in the .vcxproj.user file and nothing was applied to the project being debugged. The arguments are selected using Project.ConfigurationManager.ActiveConfiguration (see ItemAggregationService), so resolve the VCConfiguration by matching "Configuration|Platform" against VCProject.Configurations to make the read and the write agree. If no match is found the previous behaviour is used as a fallback. The VFProjEngine (Fortran) path already avoided Project.Object.ActiveConfiguration for a similar reason. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Services/ProjectConfigService.cs | 46 ++++++++++++++++++- .../source.extension.vsixmanifest | 6 +-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/SmartCmdArgs/SmartCmdArgs.Shared/Services/ProjectConfigService.cs b/SmartCmdArgs/SmartCmdArgs.Shared/Services/ProjectConfigService.cs index 23be9d4..500b3c4 100644 --- a/SmartCmdArgs/SmartCmdArgs.Shared/Services/ProjectConfigService.cs +++ b/SmartCmdArgs/SmartCmdArgs.Shared/Services/ProjectConfigService.cs @@ -349,13 +349,57 @@ private class CustomDebuggerRule return list; } + /// + /// Returns the VCConfiguration the debug settings should be written to. + /// + /// VCProject.ActiveConfiguration is not reliable, it can return a configuration which is + /// not the one currently selected (observed in VS2026). The arguments themselves are selected + /// based on Project.ConfigurationManager.ActiveConfiguration (see + /// ), so they have to be written to that very same + /// configuration. Otherwise they end up in a configuration which is not the one being debugged. + /// + /// + private static dynamic GetActiveVCConfiguration(EnvDTE.Project project, dynamic vcPrj) + { + ThreadHelper.ThrowIfNotOnUIThread(); + + try + { + var dteCfg = project?.ConfigurationManager?.ActiveConfiguration; + if (dteCfg != null) + { + // VCConfiguration.Name has the form "Configuration|Platform" + var wantedName = $"{dteCfg.ConfigurationName}|{dteCfg.PlatformName}"; + + dynamic configs = vcPrj?.Configurations; // is IVCCollection + if (configs != null) + { + for (int index = 1; index <= configs.Count; index++) + { + dynamic cfg = configs.Item(index); // is VCConfiguration + if (cfg != null && string.Equals((string)cfg.Name, wantedName, StringComparison.OrdinalIgnoreCase)) + return cfg; + } + } + + Logger.Warn($"GetActiveVCConfiguration: no VCConfiguration named '{wantedName}' found, falling back to VCProject.ActiveConfiguration"); + } + } + catch (Exception ex) + { + Logger.Error("GetActiveVCConfiguration: failed to resolve the active configuration via ConfigurationManager", ex); + } + + return vcPrj?.ActiveConfiguration; + } + private static void SetVCProjEngineConfig(EnvDTE.Project project, string arguments, IDictionary envVars, string workDir, string launchApp) { ThreadHelper.ThrowIfNotOnUIThread(); // Use late binding to support VS2015 and VS2017 dynamic vcPrj = (dynamic)project.Object; // is VCProject - dynamic vcCfg = vcPrj?.ActiveConfiguration; // is VCConfiguration + dynamic vcCfg = GetActiveVCConfiguration(project, vcPrj); // is VCConfiguration if (vcCfg == null) { diff --git a/SmartCmdArgs/SmartCmdArgs17/source.extension.vsixmanifest b/SmartCmdArgs/SmartCmdArgs17/source.extension.vsixmanifest index b228ade..66f278a 100644 --- a/SmartCmdArgs/SmartCmdArgs17/source.extension.vsixmanifest +++ b/SmartCmdArgs/SmartCmdArgs17/source.extension.vsixmanifest @@ -11,10 +11,10 @@ Commandline Command Line Arguments cmd project - + amd64 - + arm64 @@ -22,7 +22,7 @@ - +