diff --git a/MvsSln b/MvsSln index aadc022..8dd3956 160000 --- a/MvsSln +++ b/MvsSln @@ -1 +1 @@ -Subproject commit aadc0229d06b72cfcebbcca092aec88c9a012dc2 +Subproject commit 8dd3956aa8b86305d3419e697d01cd8f556673cb diff --git a/vsSolutionBuildEvent/EnvAbstract.cs b/vsSolutionBuildEvent/EnvAbstract.cs index 7fb2597..ff5ab6c 100644 --- a/vsSolutionBuildEvent/EnvAbstract.cs +++ b/vsSolutionBuildEvent/EnvAbstract.cs @@ -41,6 +41,8 @@ public abstract class EnvAbstract /// public abstract string SolutionFile { get; protected set; } + protected abstract ConfigItem ActiveSlnConf { get; } + protected abstract void UpdateSlnEnv(ISlnResult sln); /// @@ -108,16 +110,19 @@ public virtual EProject getProject(string name = null) Log.Trace($"getProject: started with '{name}' /{StartupProjectString}"); - if(String.IsNullOrEmpty(name)) { - name = StartupProjectString; - } + if(string.IsNullOrEmpty(name)) name = StartupProjectString; ProjectItem project = Sln.ProjectItems.FirstOrDefault(p => p.name == name); if(project.fullPath == null) { throw new NotFoundException($"Project '{name}' was not found. ['{project.name}', '{project.pGuid}']"); } - return SlnEnv?.GetOrLoadProject(project); + IConfPlatformPrj cfg = Sln.ProjectItemsConfigs + .FirstOrDefault(p => ActiveSlnConf?.Equals(p.solutionConfig) == true) + .projectConfig; + + return (cfg == null) ? SlnEnv?.GetOrLoadProject(project) + : SlnEnv?.GetOrLoadProject(project, cfg); } /// diff --git a/vsSolutionBuildEvent/Environment.cs b/vsSolutionBuildEvent/Environment.cs index 6a0b93e..7b2e445 100644 --- a/vsSolutionBuildEvent/Environment.cs +++ b/vsSolutionBuildEvent/Environment.cs @@ -51,13 +51,12 @@ public class Environment: EnvAbstract, IEnvironment, IEnvironmentExt, IEvEnv private string startupProject; + private ConfigItem currentSlnConf; + /// /// List of EnvDTE projects. /// - public IEnumerable ProjectsDTE - { - get => _DTEProjects; - } + public IEnumerable ProjectsDTE => _DTEProjects; /// /// List of Microsoft.Build.Evaluation projects. @@ -283,6 +282,23 @@ protected IEnumerable DTEProjectsRaw } } + protected override ConfigItem ActiveSlnConf + { + get + { + SolutionConfiguration2 cfg = SolutionActiveCfg; + if(cfg == null) return null; + + if(currentSlnConf?.IsEqualByRule(cfg.Name, cfg.PlatformName) == true) + { + return currentSlnConf; + } + + currentSlnConf = new(cfg.Name, cfg.PlatformName); + return currentSlnConf; + } + } + /// /// An unified unscoped and out of Project instance the property value by its name. /// Remarks: Any property values cannot be null. diff --git a/vsSolutionBuildEvent/IsolatedEnv.cs b/vsSolutionBuildEvent/IsolatedEnv.cs index b4bda18..f59e9bd 100644 --- a/vsSolutionBuildEvent/IsolatedEnv.cs +++ b/vsSolutionBuildEvent/IsolatedEnv.cs @@ -41,6 +41,8 @@ public class IsolatedEnv: EnvAbstract, IEnvironment, IEvEnv protected readonly IConfPlatform defaultCfg = new ConfigSln("Debug", "Any CPU"); + private ConfigItem currentSlnConf; + private string _startupProjectString; private readonly IDictionary _properties; @@ -178,6 +180,8 @@ public IOW OutputWindowPane get => __disabled(nameof(OutputWindowPane)); } + protected override ConfigItem ActiveSlnConf => extractCfg(slnProperties); + /// /// An unified unscoped and out of Project instance the property value by its name. /// Remarks: Any property values cannot be null. @@ -292,14 +296,20 @@ void _SetIfNull(string key, string value) return properties; } - protected IConfPlatform extractCfg(IDictionary properties) + protected ConfigItem extractCfg(IDictionary properties) { IConfPlatform def = Sln?.DefaultConfig; - return new ConfigItem( - properties.GetOrDefault(PropertyNames.CONFIG, def?.Configuration), - properties.GetOrDefault(PropertyNames.PLATFORM, def?.Platform) - ); + string configuration = properties.GetOrDefault(PropertyNames.CONFIG, def?.Configuration); + string platform = properties.GetOrDefault(PropertyNames.PLATFORM, def?.Platform); + + if(currentSlnConf?.IsEqualByRule(configuration, platform) == true) + { + return currentSlnConf; + } + + currentSlnConf = new(configuration, platform); + return currentSlnConf; } protected string formatCfg(IDictionary properties)