public static Models.Solution Read(string filename) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename); string name = fileInfo.Name.Substring(0, fileInfo.Name.Length - fileInfo.Extension.Length); System.IO.TextReader reader = System.IO.File.OpenText(filename); Models.Solution solution = Read(name, reader); reader.Close(); return(solution); }
public void Build(string filename, string configuration) { System.IO.FileInfo fileInfo = new System.IO.FileInfo(filename); string name = fileInfo.Name.Substring(0, fileInfo.Name.ToLower().LastIndexOf(".sln")); System.IO.TextReader reader = fileInfo.OpenText(); Models.Solution solution = SolutionReader.Read(filename, reader); reader.Close(); string projectFolder = LastLeft(filename, System.IO.Path.DirectorySeparatorChar.ToString()); this.Build(solution, configuration, projectFolder, String.Empty); }
private static void LoadProject(string line, Models.Solution solution) { string[] sublines = line.Substring(line.IndexOf("=") + 1).Split(",".ToCharArray()); string name = sublines[0].Trim().Substring(1, sublines[0].Trim().Length - 2); string path = sublines[1].Trim().Substring(1, sublines[1].Trim().Length - 2); System.Guid guid = new System.Guid(sublines[2].Trim().Substring(1, sublines[2].Trim().Length - 2)); Models.Project project = new Models.Project(); project.Name = name; project.Path = path; project.Guid = guid; solution.Projects.Add(project); }
private static void LoadConfigurations(System.IO.TextReader reader, Models.Solution solution) { while (reader.Peek() != -1) { string line = reader.ReadLine(); if (line.StartsWith(" EndGlobalSection")) { return; } Models.Config config = new Models.Config(); config.Name = line.Split("=".ToCharArray())[0].Trim(); solution.Configs.Add(config); } }
public static void Write(Models.Solution solution, System.IO.TextWriter writer) { if (!writer.Encoding.Equals(System.Text.Encoding.UTF8)) { throw new System.Exception("Solution writer requires UTF8 encoding."); } System.Text.UTF8Encoding encoding = (System.Text.UTF8Encoding)writer.Encoding; byte[] bom = encoding.GetPreamble(); if (bom.Length != 3 || bom[0] != 239 || bom[1] != 187 || bom[2] != 191) { throw new System.Exception("Solution writer requires UTF8 encoding with a Byte Order Mark."); } writer.WriteLine(""); writer.WriteLine("Microsoft Visual Studio Solution File, Format Version 9.00"); writer.WriteLine("# Visual Studio 2005"); foreach (Models.Project project in solution.Projects) { writer.WriteLine("Project(\"{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}\") = \"" + project.Name + "\", \"" + project.Path + "\", \"{" + project.Guid.ToString().ToUpper() + "}\""); writer.WriteLine("EndProject"); } writer.WriteLine("Global"); writer.WriteLine(" GlobalSection(SolutionConfigurationPlatforms) = preSolution"); writer.WriteLine(" Debug|Any CPU = Debug|Any CPU"); writer.WriteLine(" Release|Any CPU = Release|Any CPU"); writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(ProjectConfigurationPlatforms) = postSolution"); foreach (Models.Project project in solution.Projects) { writer.WriteLine(" {"+ project.Guid.ToString().ToUpper() + "}.Debug|Any CPU.ActiveCfg = Debug|Any CPU"); writer.WriteLine(" {"+ project.Guid.ToString().ToUpper() + "}.Debug|Any CPU.Build.0 = Debug|Any CPU"); writer.WriteLine(" {"+ project.Guid.ToString().ToUpper() + "}.Release|Any CPU.ActiveCfg = Release|Any CPU"); writer.WriteLine(" {"+ project.Guid.ToString().ToUpper() + "}.Release|Any CPU.Build.0 = Release|Any CPU"); } writer.WriteLine(" EndGlobalSection"); writer.WriteLine(" GlobalSection(SolutionProperties) = preSolution"); writer.WriteLine(" HideSolutionNode = FALSE"); writer.WriteLine(" EndGlobalSection"); writer.WriteLine("EndGlobal"); writer.Flush(); }
public static Models.Solution Read(string name, System.IO.TextReader reader) { Models.Solution solution = new Models.Solution(); solution.Name = name; reader.ReadLine(); while (reader.Peek() != -1) { string line = reader.ReadLine(); if (line.StartsWith("Project")) { LoadProject(line, solution); } else if (line.StartsWith(" GlobalSection(SolutionConfiguration)")) { LoadConfigurations(reader, solution); } } return(solution); }