public void Save(TextWriter writer) { writer.WriteLine(Header, _fileFormatVersion); foreach (SlnProject project in _projects) { writer.WriteLine($@"Project(""{project.ProjectTypeGuid}"") = ""{project.Name}"", ""{project.FullPath}"", ""{project.ProjectGuid}"""); writer.WriteLine("EndProject"); } if (SolutionItems.Count > 0) { writer.WriteLine($@"Project(""{SlnFolder.ProjectTypeGuid}"") = ""Solution Items"", ""Solution Items"", ""{Guid.NewGuid().ToSolutionString()}"" "); writer.WriteLine(" ProjectSection(SolutionItems) = preProject"); foreach (string solutionItem in SolutionItems) { writer.WriteLine($" {solutionItem} = {solutionItem}"); } writer.WriteLine(" EndProjectSection"); writer.WriteLine("EndProject"); } SlnHierarchy hierarchy = SlnHierarchy.FromProjects(_projects); if (hierarchy.Folders.Count > 0) { foreach (SlnFolder folder in hierarchy.Folders) { writer.WriteLine($@"Project(""{folder.TypeGuid}"") = ""{folder.Name}"", ""{folder.FullPath}"", ""{folder.Guid}"""); writer.WriteLine("EndProject"); } } writer.WriteLine("Global"); writer.WriteLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution"); foreach (string configuration in _configurations) { foreach (string platform in _platforms) { writer.WriteLine($" {configuration}|{platform} = {configuration}|{platform}"); } } writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(ProjectConfigurationPlatforms) = preSolution"); foreach (SlnProject project in _projects) { foreach (string configuration in _configurations) { foreach (string platform in _platforms) { writer.WriteLine($@" {project.ProjectGuid}.{configuration}|{platform}.ActiveCfg = {configuration}|{platform}"); writer.WriteLine($@" {project.ProjectGuid}.{configuration}|{platform}.Build.0 = {configuration}|{platform}"); } } } writer.WriteLine(" EndGlobalSection"); if (_projects.Count > 1) { writer.WriteLine(@" GlobalSection(NestedProjects) = preSolution"); foreach (KeyValuePair <string, string> nestedProject in hierarchy.Hierarchy) { writer.WriteLine($@" {nestedProject.Key} = {nestedProject.Value}"); } writer.WriteLine(" EndGlobalSection"); } writer.WriteLine("EndGlobal"); }
public void Save(TextWriter writer, bool folders) { writer.WriteLine(Header, _fileFormatVersion); foreach (SlnProject project in _projects) { writer.WriteLine($@"Project(""{project.ProjectTypeGuid.ToSolutionString()}"") = ""{project.Name}"", ""{project.FullPath}"", ""{project.ProjectGuid.ToSolutionString()}"""); writer.WriteLine("EndProject"); } if (SolutionItems.Count > 0) { writer.WriteLine($@"Project(""{SlnFolder.FolderProjectTypeGuid.ToSolutionString()}"") = ""Solution Items"", ""Solution Items"", ""{Guid.NewGuid().ToSolutionString()}"" "); writer.WriteLine(" ProjectSection(SolutionItems) = preProject"); foreach (string solutionItem in SolutionItems) { writer.WriteLine($" {solutionItem} = {solutionItem}"); } writer.WriteLine(" EndProjectSection"); writer.WriteLine("EndProject"); } SlnHierarchy hierarchy = null; if (folders) { hierarchy = SlnHierarchy.FromProjects(_projects); if (hierarchy.Folders.Count > 0) { foreach (SlnFolder folder in hierarchy.Folders) { writer.WriteLine($@"Project(""{folder.ProjectTypeGuid.ToSolutionString()}"") = ""{folder.Name}"", ""{folder.FullPath}"", ""{folder.FolderGuid.ToSolutionString()}"""); writer.WriteLine("EndProject"); } } } writer.WriteLine("Global"); writer.WriteLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution"); IEnumerable <string> globalConfigurations = new HashSet <string>(_projects.SelectMany(p => p.Configurations)).Distinct(); IEnumerable <string> globalPlatforms = new HashSet <string>(_projects.SelectMany(p => p.Platforms)).Distinct().ToList(); foreach (string configuration in globalConfigurations) { foreach (string platform in globalPlatforms) { if (!string.IsNullOrWhiteSpace(configuration) && !string.IsNullOrWhiteSpace(platform)) { writer.WriteLine($" {configuration}|{platform} = {configuration}|{platform}"); } } } writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(ProjectConfigurationPlatforms) = preSolution"); foreach (SlnProject project in _projects) { foreach (string configuration in project.Configurations) { foreach (string platform in project.Platforms) { if (!string.IsNullOrWhiteSpace(configuration) && !string.IsNullOrWhiteSpace(platform)) { writer.WriteLine($@" {project.ProjectGuid.ToSolutionString()}.{configuration}|{platform}.ActiveCfg = {configuration}|{platform}"); writer.WriteLine($@" {project.ProjectGuid.ToSolutionString()}.{configuration}|{platform}.Build.0 = {configuration}|{platform}"); } } } } writer.WriteLine(" EndGlobalSection"); if (folders && _projects.Count > 1) { writer.WriteLine(@" GlobalSection(NestedProjects) = preSolution"); foreach (KeyValuePair <Guid, Guid> nestedProject in hierarchy.Hierarchy) { writer.WriteLine($@" {nestedProject.Key.ToSolutionString()} = {nestedProject.Value.ToSolutionString()}"); } writer.WriteLine(" EndGlobalSection"); } writer.WriteLine("EndGlobal"); }