I am new to powershell and I wanted to change version in an xml file after every deployment and. I referred to Unable to update a value in msbuild proj file using powershell
AppVersion
is the value of an attribute of an <add>
node, not the name of a node. Also, you want to extract the value of the node's value
attribute, not the node's innerText
.
,- node name
/
/ ,- attribute name
/ /
/ / ,- attribute value
/ / /
<add key="AppVersion" value="v0.1.7.21.31.144402">
something
</add> \
`- inner text
Attributes are selected in XPath expressions like this:
//node[@attribute='value']
Change these two lines:
$node = $Test1QABuildVersion.SelectSingleNode("/configuration/site/key/AppVersion")
$PropertyVersion= $node.InnerText
into this:
$node = $Test1QABuildVersion.SelectSingleNode("/configuration/site/add[@key='AppVersion']")
$PropertyVersion= $node.value
and update the version number like this:
$node.value = $newVersion