Increase version of application.config automatically using powershell after every deployment



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. Below is the xml content:



<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<site>


<add key="ShowAppConf" value="true"/>
<add key="site.IsCsrfCheck" value="false" />
<add key="EnableDeviceFileAuthentication" value="false" />
<add key="EnableFileAuthentication" value="false" />
<add key="AppVersion" value="v0.1.7.21.31.144402" />


</site>
</configuration>


and I am trying to increase value of revision version of AppVersion by using:



$Test1QAMSBuildFile = 'D:\test\application.config.xml'
[xml]$Test1QABuildVersion = Get-Content $Test1QAMSBuildFile
$node = $Test1QABuildVersion.SelectSingleNode("/configuration/site/key/AppVersion")
$PropertyVersion= $node.InnerText
$UpdateVersion= $PropertyVersion.split(".")
$UpdateVersion[4] = (($UpdateVersion[3] -as [int]) + 1).ToString()
$newVersion = $UpdateVersion -join '.'
$node.InnerText = $newVersion
$Test1QABuildVersion.Save($Test1QAMSBuildFile)


After running this script powershell ise throws error:



You cannot call a method on a null-valued expression.
At line:5 char:1
+ $UpdateVersion= $PropertyVersion.split(".")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull

Cannot index into a null array.
At line:6 char:1
+ $UpdateVersion[4] = (($UpdateVersion[3] -as [int]) + 1).ToString()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray

The property 'InnerText' cannot be found on this object. Verify that the property exists and can be set.
At line:8 char:1
+ $node.InnerText = $newVersion
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound


How do I increase version automatically using powershell.


No comments:

Post a Comment