Exemplo n.º 1
0
        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);
        }