private void RemoveProjectFromSolution(string slnFile, string destFile) { if (slnFile == null) throw new ArgumentNullException("slnFile"); if (destFile == null) throw new ArgumentNullException("destFile"); if (!File.Exists(slnFile)) throw new ArgumentException( string.Format("Can not found file \"{0}\".", slnFile)); if (!ForceOverwrite && File.Exists(destFile)) throw new ArgumentException(string.Format ("Destination file \"{0}\" already exists, " + "You can use ForceOverwrite to force overwrite file.", destFile)); var sln = new SolutionInfo(slnFile); foreach (var e in ProjectNamePatterns) { var pattern = e; sln.RemoveProjects(p => new Regex(pattern).IsMatch(p.ProjectName)); } foreach (var e in ItemPatterns) { var pattern = e; sln.RemoveSolutionItems(m => new Regex(pattern).IsMatch(m)); } File.WriteAllText(destFile, sln.ToString(), new UTF8Encoding(true, true)); }