Surgical XML editing with Powershell Surgical XML editing with Powershell powershell powershell

Surgical XML editing with Powershell


I did a lot of VS project manipulation a few years back. Seems like creating the XmlDocument and using Load directly (versus using Get-Content and casting to XML) worked better for me:

$path = "C:\temp\foo.csproj"$proj = new-object system.xml.xmldocument$proj.PreserveWhitespace = $true$proj.Load($path)...$proj.Save($path)

Update - Try setting the PreserveWhitespace property to true before loading the XML document as shown above.