Add/remove projects also updates build configurations (#5134)
* Add/remove projects also updates build configurations * Fix the algorithm for adding/removing build configurations * Address PR comments
This commit is contained in:
parent
06d33f01ce
commit
19b4bad315
16 changed files with 550 additions and 43 deletions
|
@ -49,6 +49,8 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectFromSolution
|
|||
slnChanged |= RemoveProject(slnFile, path);
|
||||
}
|
||||
|
||||
RemoveEmptyConfigurationSections(slnFile);
|
||||
|
||||
if (slnChanged)
|
||||
{
|
||||
slnFile.Write();
|
||||
|
@ -75,6 +77,11 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectFromSolution
|
|||
{
|
||||
foreach (var slnProject in projectsToRemove)
|
||||
{
|
||||
var buildConfigsToRemove = slnFile.ProjectConfigurationsSection.GetPropertySet(slnProject.Id);
|
||||
if (buildConfigsToRemove != null)
|
||||
{
|
||||
slnFile.ProjectConfigurationsSection.Remove(buildConfigsToRemove);
|
||||
}
|
||||
slnFile.Projects.Remove(slnProject);
|
||||
Reporter.Output.WriteLine(
|
||||
string.Format(CommonLocalizableStrings.ProjectReferenceRemoved, slnProject.FilePath));
|
||||
|
@ -85,5 +92,23 @@ namespace Microsoft.DotNet.Tools.Remove.ProjectFromSolution
|
|||
|
||||
return projectRemoved;
|
||||
}
|
||||
|
||||
private void RemoveEmptyConfigurationSections(SlnFile slnFile)
|
||||
{
|
||||
if (slnFile.Projects.Count == 0)
|
||||
{
|
||||
var solutionConfigs = slnFile.Sections.GetSection("SolutionConfigurationPlatforms");
|
||||
if (solutionConfigs != null)
|
||||
{
|
||||
slnFile.Sections.Remove(solutionConfigs);
|
||||
}
|
||||
|
||||
var projectConfigs = slnFile.Sections.GetSection("ProjectConfigurationPlatforms");
|
||||
if (projectConfigs != null)
|
||||
{
|
||||
slnFile.Sections.Remove(projectConfigs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue