private void WriteContent(FolderContent content, StringBuilder projectSection, StringBuilder folderSection, StringBuilder buildConfigSection) { foreach (var dir in content.SubDirectories) { projectSection.AppendLine($"Project(\"{{2150E333-8FDC-42A3-9474-1A3956D46DE8}}\") = \"{ Path.GetFileName(dir.Path) }\", \"{ Path.GetFileName(dir.Path) }\", \"{{{dir.FolderId.Value}}}\""); projectSection.AppendLine("EndProject"); if (!content.IsRoot) { folderSection.AppendLine($" {{{dir.FolderId.Value}}} = {{{content.FolderId.Value}}}"); } WriteContent(dir, projectSection, folderSection, buildConfigSection); } foreach (var project in content.Projects) { var projectId = File.ReadAllText(Path.Combine(content.Path, project)); projectId = projectId.Substring(projectId.IndexOf("<ProjectGuid>") + 14, 36); projectSection.AppendLine($"Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{ Path.GetFileNameWithoutExtension(project) }\", \"{ MakeRelative(project) }\", \"{{{projectId}}}\""); projectSection.AppendLine("EndProject"); if (!content.IsRoot) { folderSection.AppendLine($" {{{projectId}}} = {{{content.FolderId.Value}}}"); } buildConfigSection.AppendLine($" {{{projectId}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU"); buildConfigSection.AppendLine($" {{{projectId}}}.Debug|Any CPU.Build.0 = Debug|Any CPU"); buildConfigSection.AppendLine($" {{{projectId}}}.Release|Any CPU.ActiveCfg = Debug|Any CPU"); buildConfigSection.AppendLine($" {{{projectId}}}.Release|Any CPU.Build.0 = Debug|Any CPU"); } }
FolderContent GetContent(string folder) { if (_args.Verbose) { Console.WriteLine(folder); } var content = new FolderContent(); content.Path = folder; try { foreach (var subFolder in Directory.GetDirectories(folder)) { if (_excludedFolders.Contains(Path.GetFileName(subFolder))) { continue; } var subContent = GetContent(subFolder); if (subContent.IsEmpty()) { continue; } else if (subContent.SubDirectories.Count() == 0 && subContent.Projects.Count() == 1) { content.Projects.AddRange(subContent.Projects); // Flatten folders with only one project. } else { content.SubDirectories.Add(subContent); } } } catch (PathTooLongException) { Console.Error.WriteLine($"PathTooLongException: {folder}"); } try { foreach (var subProj in Directory.GetFiles(folder, "*.CSPROJ")) { content.Projects.Add(subProj); } } catch (PathTooLongException) { Console.Error.WriteLine($"PathTooLongException: {folder}"); } return(content); }