3F / MvsSln

🧩 Customizable VisualStudio .sln parser with project support (.vcxproj, .csproj., …). Pluggable lightweight r/w handlers at runtime, and more …
MIT License
140 stars 27 forks source link

Configurations and Projects/Colutions Oh My... #40

Closed DynConcepts closed 3 years ago

DynConcepts commented 3 years ago

The VS GUI allows you do delete a Solution config, but that does not iterate through projects. I want to delete "ALL" project configurations and platforms except for a specific one...

I can iterate through them and identify them, but can not find the object to call a "remove like" method on...

var allprojectConfigs = data.ProjectItemsConfigs.ToList(); List<ProjectItemCfg> toRemove = new List<ProjectItemCfg>(); foreach (ProjectItemCfg projectConfig in allprojectConfigs) { if (projectConfig.projectConfig.Platform == "x64") { Microsoft.Build.Evaluation.Project loadedProject = sln.Result.Env.GetOrLoadProject(projectConfig.project); toRemove.Add(projectConfig); } } // OK, now kill everything in the "toRemove" list"

DynConcepts commented 3 years ago

Additional info... This would also need to remove any other elements that were specific to the removed configuration/platform. At this point pretty sure that the package does not support this as a single call (but still hopeful), but perhaps someone has previously developed a snipped and can share.

NOTE: The Project Configuration/Platform most likely does NOT exist in the Solution!!!!!!

3F commented 3 years ago

How about

using var sln = new Sln(@"D:\prg\issues\MvsSln\issue40\TestStruct\TestStruct.sln", SlnItems.Env);
sln.Result.Env
    .LoadProjects(sln.Result.ProjectItemsConfigs.Where(p => p.solutionConfig.Platform == "x64"))
    .ForEach(xp => // TODO: more like we need add this as part of MvsSln, https://github.com/3F/DllExport/blob/c1cc52fa13f563f97a2b4fe08bfb541c69195866/Wizard/Extensions/XProjectExtension.cs#L121
        xp.Project.Xml.PropertyGroups.Where(p =>
                // NOTE: projectConfig should contain default IRuleOfConfig impl to avoid misunderstanding between "Any CPU" and "AnyCPU", or like;
                // MS "Any CPU" bug was described here: https://github.com/3F/vsSolutionBuildEvent/issues/14#issuecomment-246419276
                p.Condition.Contains($"'{xp.ProjectItem.projectConfig.ConfigurationByRule}|{xp.ProjectItem.projectConfig.PlatformByRule}'")
        )
        .ForEach(p => p.Parent?.RemoveChild(p))
        .E(_ => xp.Save())
    );

NOTE: The Project Configuration/Platform most likely does NOT exist in the Solution!!!!!!

Make sure about the "Any CPU" / "AnyCPU". You can simply use the default rules or implement something for the mentioned IRuleOfConfig

This would also need to remove any other elements that were specific to the removed configuration/platform.

Just add something else together with PropertyGroups logic above