I work with csproj files using Powershell to do large-scale editing of project links. So far, I have been able to edit the Include attributes on ProjectReferences using the following lines:
$projectXml = [xml](Get-Content $_.Project.FullName) Add-TfsPendingChange -edit $_.Project.FullName -ErrorAction Stop $projectXml | Select-Xml -namespace @{msb = "http://schemas.microsoft.com/developer/msbuild/2003"} -xpath "//msb:ProjectReference[msb:Project='$projectGuid']" | Select-Object -ExpandProperty Node | foreach { $_.Include = "$newPath" } $projectXml.Save($_.Project.FullName)
This works and replaces the Include attribute with the corresponding ProjectReferences, as I expect. However, there are many additional βharmlessβ changes, such as formatting all tags on their own line, for example.
<FileUpgradeFlags></FileUpgradeFlags>
becomes
<FileUpgradeFlags>
</FileUpgradeFlags>
Is there a way to do an edit that does not have these side effects?
edit: for clarity, for anyone who finds this message for other reasons, Select-MsBuildXml is just a wrapper function that I wrote in Select-Xml that preloads the namespace parameter in the msbuild namespace and extends the node property after that.
xml formatting powershell side-effects select-xml
bwerks
source share