Set-XmlPoke.ps1
function Set-XmlPoke { <# .SYNOPSIS 使用xpath修改xml元素值 .DESCRIPTION Set-XmlPoke -filePath "./abc.csproj" -xpath "/Project/PropertyGroup/Version" -Value "2.0.0" #> param ( [Parameter(Mandatory)][string]$filePath, [Parameter(Mandatory)][string]$xpath, [Parameter(Mandatory)][string]$value ) $versionXml = [xml](get-content $filePath) $appVersionNode = $versionXml.SelectSingleNode($xpath) $appVersionNode.RemoveAll() $appVersionNode.AppendChild($versionXml.CreateTextNode($value.ToString())) | out-null $versionXml.Save((Resolve-Path $filePath)) } |