2
我是PowerShell的新手,我想在每次部署和更新後都在xml文件中更改版本。我提到Unable to update a value in msbuild proj file using powershell。下面是XML內容:在每次部署之後使用powershell自動增加application.config版本
<?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>
,我試圖通過增加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(".")
$UpdateVersion[4] = (($UpdateVersion[4] -as [int]) + 1).ToString()
$newVersion = $UpdateVersion -join '.'
$node.InnerText = $newVersion
$Test1QABuildVersion.Save($Test1QAMSBuildFile)
運行此腳本PowerShell ISE中後拋出錯誤:
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
如何使用PowerShell自動增加版本。
Thankyou @Ansgar Wiechers。這現在完美。 – 2014-10-28 12:00:20