Files
DotNetSolutionTools/DotNetSolutionTools.Core/FormatCsproj.cs
Matthew Parker fc55b195d6 App layout
2023-08-31 23:38:32 +10:00

37 lines
852 B
C#

using System.Text;
using System.Xml;
namespace DotNetSolutionTools.Core;
public static class FormatCsproj
{
public static void FormatCsprojFile(string csprojFilePath)
{
using TextReader rd = new StreamReader(csprojFilePath, Encoding.Default);
XmlDocument doc = new XmlDocument();
doc.Load(rd);
if (rd != Console.In)
{
rd.Close();
}
using var wr = new StreamWriter(csprojFilePath, false, Encoding.Default);
var settings = new XmlWriterSettings
{
Indent = true,
IndentChars = "\t",
NewLineOnAttributes = false,
OmitXmlDeclaration = true
};
using (var writer = XmlWriter.Create(wr, settings))
{
doc.WriteContentTo(writer);
writer.Close();
}
}
}