27 using System.Collections.Generic;
31 namespace SiliconStudio.Core.VisualStudio
33 internal class SolutionWriter : IDisposable
35 private StreamWriter writer;
37 public SolutionWriter(
string solutionFullPath) : this(new FileStream(solutionFullPath,
FileMode.
Create, FileAccess.
Write))
41 public SolutionWriter(
Stream writer)
43 this.writer =
new StreamWriter(writer,
Encoding.UTF8);
55 public void WriteSolutionFile(Solution solution)
59 WriteHeader(solution);
60 WriteProjects(solution);
61 WriteGlobal(solution);
65 private void WriteGlobal(Solution solution)
67 writer.WriteLine(
"Global");
68 WriteGlobalSections(solution);
69 writer.WriteLine(
"EndGlobal");
72 private void WriteGlobalSections(Solution solution)
74 foreach (Section globalSection
in solution.GlobalSections)
76 var propertyLines =
new List<PropertyItem>(globalSection.Properties);
77 switch (globalSection.Name)
79 case "NestedProjects":
80 foreach (
Project project
in solution.Projects)
82 if (project.ParentGuid != Guid.Empty)
84 propertyLines.Add(
new PropertyItem(project.Guid.ToString(
"B").ToUpperInvariant(), project.ParentGuid.ToString(
"B").ToUpperInvariant()));
89 case "ProjectConfigurationPlatforms":
90 foreach (
Project project
in solution.Projects)
92 foreach (PropertyItem propertyLine
in project.PlatformProperties)
96 string.Format(
"{0}.{1}", project.Guid.ToString(
"B").ToUpperInvariant(), propertyLine.Name),
103 if (globalSection.Name.EndsWith(
"Control", StringComparison.InvariantCultureIgnoreCase))
106 foreach (
Project project
in solution.Projects)
108 if (project.VersionControlProperties.Count > 0)
110 foreach (PropertyItem propertyLine
in project.VersionControlProperties)
114 string.Format(
"{0}{1}", propertyLine.Name, index),
115 propertyLine.Value));
121 propertyLines.Insert(0,
new PropertyItem(
"SccNumberOfProjects", index.ToString()));
126 WriteSection(globalSection, propertyLines);
130 private void WriteHeader(Solution solution)
134 if (solution.Headers.Count == 0 || solution.Headers[0].Trim().Length > 0)
139 foreach (
string line
in solution.Headers)
141 writer.WriteLine(line);
144 foreach (PropertyItem propertyLine
in solution.Properties)
146 writer.WriteLine(
"{0} = {1}", propertyLine.Name, propertyLine.Value);
150 private void WriteProjects(Solution solution)
152 foreach (
Project project
in solution.Projects)
154 writer.WriteLine(
"Project(\"{0}\") = \"{1}\", \"{2}\", \"{3}\"",
155 project.TypeGuid.ToString(
"B").ToUpperInvariant(),
157 project.RelativePath,
158 project.Guid.ToString(
"B").ToUpperInvariant());
159 foreach (Section projectSection
in project.Sections)
161 WriteSection(projectSection, projectSection.Properties);
163 writer.WriteLine(
"EndProject");
169 writer.WriteLine(
"\t{0}({1}) = {2}", section.SectionType, section.Name, section.Step);
170 foreach (PropertyItem propertyLine
in propertyLines)
172 writer.WriteLine(
"\t\t{0} = {1}", propertyLine.Name, propertyLine.Value);
174 writer.WriteLine(
"\tEnd{0}", section.SectionType);
System.Text.Encoding Encoding
System.IO.FileMode FileMode
Creates a new file, always. If a file exists, the function overwrites the file, clears the existing a...