public static void RemoveProject(string rootDirectory, string filePath, string projectName) { var builder = new StringBuilder(); using (var reader = File.OpenText(filePath)) { IReference reference = null; var nextLineIsEndProjectForReference = false; var lineText = reader.ReadLine(); while (lineText != null) { if ( reference == null && SolutionReference.TryParse(rootDirectory, filePath, lineText, out reference)) { if (reference.Name != projectName) { builder.AppendLine(lineText); reference = null; } else { nextLineIsEndProjectForReference = true; } lineText = reader.ReadLine(); continue; } if (nextLineIsEndProjectForReference) { nextLineIsEndProjectForReference = false; } else if (reference == null || !lineText.Contains(reference.Guid)) { builder.AppendLine(lineText); } lineText = reader.ReadLine(); } reader.Close(); } File.WriteAllText(filePath, builder.ToString()); }
public static bool TryParse(string rootDirectory, string slnFilePath, out Solution solution) { solution = null; if (string.IsNullOrEmpty(slnFilePath)) { return(false); } solution = new Solution(rootDirectory, slnFilePath); try { using (var reader = File.OpenText(slnFilePath)) { var lineText = reader.ReadLine(); while (lineText != null) { IReference reference; if (SolutionReference.TryParse(rootDirectory, slnFilePath, lineText, out reference)) { solution._references.Add(reference); } lineText = reader.ReadLine(); } reader.Close(); } } catch (Exception) { return(false); } return(true); }