public void Save(string fileName) { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. if (!this.Settings.MaintainOriginalItemOrder) { ItemGroups.Each(group => { XmlElement[] elements = null; elements = @group.Items.Select(x => x.Element).OrderBy(x => x.GetAttribute("Include")).ToArray(); group.Element.RemoveAll(); elements.Each(x => group.Element.AppendChild(x)); }); } var sw = new ProjectWriter(bom); sw.NewLine = newLine; doc.Save(sw); string content = sw.ToString(); if (endsWithEmptyLine && !content.EndsWith(newLine)) content += newLine; var shouldSave = !this.Settings.OnlySaveIfChanged || (File.Exists(fileName) && !File.ReadAllText(fileName).Equals(content)); if (shouldSave) new FileSystem().WriteStringToFile(fileName, content); }
public void Save(string fileName) { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ProjectWriter sw = new ProjectWriter(bom); sw.NewLine = newLine; doc.Save(sw); string content = sw.ToString(); if (endsWithEmptyLine && !content.EndsWith(newLine)) { content += newLine; } TextFile.WriteFile(fileName, content, bom, true); }
public string SaveToString() { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ProjectWriter sw = new ProjectWriter(bom); sw.NewLine = newLine; doc.Save(sw); string content = sw.ToString(); if (endsWithEmptyLine && !content.EndsWith(newLine)) { content += newLine; } return(content); }
string SaveToString(WriteContext ctx) { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ProjectWriter sw = new ProjectWriter(format.ByteOrderMark); sw.NewLine = format.NewLine; var xw = XmlWriter.Create(sw, new XmlWriterSettings { OmitXmlDeclaration = !hadXmlDeclaration, NewLineChars = format.NewLine, NewLineHandling = NewLineHandling.Replace }); MSBuildWhitespace.Write(initialWhitespace, xw); Save(xw); xw.Dispose(); return(sw.ToString()); }
public string SaveToString () { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ProjectWriter sw = new ProjectWriter (bom); sw.NewLine = newLine; doc.Save (sw); string content = sw.ToString (); if (endsWithEmptyLine && !content.EndsWith (newLine)) content += newLine; return content; }
public void Save (string fileName) { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ProjectWriter sw = new ProjectWriter (bom); sw.NewLine = newLine; doc.Save (sw); string content = sw.ToString (); if (endsWithEmptyLine && !content.EndsWith (newLine)) content += newLine; TextFile.WriteFile (fileName, content, bom, true); }
string SaveToString (WriteContext ctx) { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ProjectWriter sw = new ProjectWriter (format.ByteOrderMark); sw.NewLine = format.NewLine; var xw = XmlWriter.Create (sw, new XmlWriterSettings { OmitXmlDeclaration = !hadXmlDeclaration, NewLineChars = format.NewLine, NewLineHandling = NewLineHandling.Replace }); MSBuildWhitespace.Write (initialWhitespace, xw); Save (xw); xw.Dispose (); return sw.ToString (); }
public void Save(string fileName) { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ItemGroups.Each(group => { var elements = group.Items.Select(x => x.Element).OrderBy(x => x.GetAttribute("Include")).ToArray(); group.Element.RemoveAll(); elements.Each(x => group.Element.AppendChild(x)); }); var sw = new ProjectWriter(bom); sw.NewLine = newLine; doc.Save(sw); string content = sw.ToString(); if (endsWithEmptyLine && !content.EndsWith(newLine)) content += newLine; new FileSystem().WriteStringToFile(fileName, content); }
public void Save(string fileName) { // StringWriter.Encoding always returns UTF16. We need it to return UTF8, so the // XmlDocument will write the UTF8 header. ItemGroups.Each(group => { var items = group.Items.ToArray(); group.Element.RemoveAll(); var orderedItems = items.OrderBy(x => x.Name).ThenBy(x => x.Include); orderedItems .Each(item => group.AddNewItem(item.Name, item.Include)); }); var sw = new ProjectWriter(bom); sw.NewLine = newLine; doc.Save(sw); string content = sw.ToString(); if (endsWithEmptyLine && !content.EndsWith(newLine)) content += newLine; new FileSystem().WriteStringToFile(fileName, content); }