Add/remove solution items based on directory structure (#5197)

* WIP support solution folders for dotnet add and remove

* Add/remove solution folders based on directory hierarchy

* Fix tests

* Disable the solution building tests

* Address PR comments

* Fix a build break due to a new tool version used in the build

* Create SlnProjectExtensions and SlnProjectCollectionExtensions per PR comments
This commit is contained in:
Justin Goshi 2017-01-04 18:32:09 -10:00 committed by GitHub
parent 05b448944c
commit d0151a6111
23 changed files with 757 additions and 46 deletions

View file

@ -106,6 +106,8 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToSolution
AddDefaultBuildConfigurations(slnFile, slnProject);
AddSolutionFolders(slnFile, slnProject);
slnFile.Projects.Add(slnProject);
Reporter.Output.WriteLine(
@ -168,5 +170,39 @@ namespace Microsoft.DotNet.Tools.Add.ProjectToSolution
}
}
}
private void AddSolutionFolders(SlnFile slnFile, SlnProject slnProject)
{
var solutionFolders = slnProject.GetSolutionFoldersFromProject();
if (solutionFolders.Any())
{
var nestedProjectsSection = slnFile.Sections.GetOrCreateSection(
"NestedProjects",
SlnSectionType.PreProcess);
string parentDirGuid = null;
foreach (var dir in solutionFolders)
{
var solutionFolder = new SlnProject
{
Id = Guid.NewGuid().ToString("B").ToUpper(),
TypeGuid = ProjectTypeGuids.SolutionFolderGuid,
Name = dir,
FilePath = dir
};
slnFile.Projects.Add(solutionFolder);
if (parentDirGuid != null)
{
nestedProjectsSection.Properties[solutionFolder.Id] = parentDirGuid;
}
parentDirGuid = solutionFolder.Id;
}
nestedProjectsSection.Properties[slnProject.Id] = parentDirGuid;
}
}
}
}