xml - Increase version of application.config automatically using powershell after every deployment -
I'm new to the powers and I wanted to change the version in an xml file after each deployment. I said. Below is the XML content:
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; Configuration & gt; & Lt; Site & gt; & Lt; Add key = "ShowAppConf" value = "true" /> & Lt; Add Key = "site.IsCsrfCheck" value = "false" /> & Lt; Add Key = "EnableDeviceFileAuthentication" value = "false" /> & Lt; Add key = "EnableFileAuthentication" value = "false" /> & Lt; Add key = "AppVersion" value = "v0.1.7.21.31.144402" /> & Lt; / Site & gt; & Lt; / Configuration & gt;
And I'm trying to increase the value of the revision version of AppVersion:
$ Test1QAMSBuildFile = 'D: \ test \ application.config.xml '[XML] $ Test1QABuildVersion = get-content $ Test1QAMSBuildFile $ node = $ Test1QABuildVersion.SelectSingleNode ( "/ configuration / site / key / AppVersion") $ PropertyVersion = $ node.InnerText $ UpdateVersion = $ PropertyVersion .split (".") $ Update description [4] = (($ update version [4] -a [int]) + 1). String () $ new version = $ update description -join '.' $ Node.InnerText = $ NewVersion $ Test1QABuildVersion.Save ($ Test1QAMSBuildFile)
throws an error after you run this script powershell ISE:
a method call Can not place a null-valuable expression on line: 5 characters: 1 + $ updateWarson = $ property version (".") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Category Information: Invalid Operation: (:) [], Runtime Expansion + Fully Qualified Errorsid: InvokeMethodOnNull can not index in a null array. In line: 6 characters: 1 + $ update warsons [4] = (($ update warsons [3] -s [int]) + 1) .ostring () + ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ + Series Info: Amanyopreshn: (:) [] runtime Akspasn + Fulkwaiclaijd Arroriaidi: Nlarere can not find the property 'Inrtekst on this object. Verify that the property exists and can be set. On line: 8 characters: 1 + $ node. Inrtekst = $ Nuwarsn + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Series information: Amanyopreshn: (:) [], RuntimeException + FullyQualifiedErrorId: PropertyNotFound
how
ap version
a & lt; Add & gt;
The value of the attribute of the node is not the name of the node. Also, you want to remove the value of the value
attribute of the node, not the inner text of the node
.
, - node name / /, - attribute name / / / /, - attribute value / / / & lieutenant; Ad key = "ap version" value = "v0.1.7.21.31.144402" & gt; Some & lt; / Add & gt; \ "- Internal text
properties are selected in XPath expressions such as:
// node [@ attribute = 'value']
to change these two lines:
$ node = $ Test1QABuildVersion.SelectSingleNode ( "/ configuration / site / key / AppVersion " ) $ PropertyVersion = $ node innerText
in this :.
$ node = $ Test1QABuildVersion.SelectSingleNode ( "/ configuration / Site / [$ key = 'AppVersion'] Add) $ PropertyVersion = $ node Value
and update version number like this:
$ node.value = $ newVersion
< / Pre>
Comments
Post a Comment