2016-04-29 7 views
2

アセンブリバージョンを置き換えるpowershellスクリプトがありますが、3番目のバージョンでバージョン番号を変更する必要があります LIKE [assembly:AssemblyVersion( "1.0.20.1")] to [アセンブリ:のAssemblyVersion(「1.0.21.1」)]powershellスクリプトでアセンブリバージョンの3番目の位置を置き換える方法

これが最後のpostionインクリメントされ、私が持っているものです。

# 
# This script will increment the build number in an AssemblyInfo.cs file 
# 

$assemblyInfoPath = "C:\Users\kondas\Desktop\PowerShell\AssemblyInfo.cs" 

$contents = [System.IO.File]::ReadAllText($assemblyInfoPath) 

$versionString = [RegEx]::Match($contents,"(AssemblyFileVersion\("")(?:\d+\.\d+\.\d+\.\d+)(""\))") 
Write-Host ("AssemblyFileVersion: " +$versionString) 

#Parse out the current build number from the AssemblyFileVersion 
$currentBuild = [RegEx]::Match($versionString,"(\.)(\d+)(""\))").Groups[2] 
Write-Host ("Current Build: " + $currentBuild.Value) 

#Increment the build number 
$newBuild= [int]$currentBuild.Value + 1 
Write-Host ("New Build: " + $newBuild) 

#update AssemblyFileVersion and AssemblyVersion, then write to file 


Write-Host ("Setting version in assembly info file ") 
$contents = [RegEx]::Replace($contents, "(AssemblyVersion\(""\d+\.\d+\.\d+\.)(?:\d+)(""\))", ("`${1}" + $newBuild.ToString() + "`${2}")) 
$contents = [RegEx]::Replace($contents, "(AssemblyFileVersion\(""\d+\.\d+\.\d+\.)(?:\d+)(""\))", ("`${1}" + $newBuild.ToString() + "`${2}")) 
[System.IO.File]::WriteAllText($assemblyInfoPath, $contents) 

答えて

1

私は個人的に様々な部品の値とそれから対象になるだろう後で必要な部分を増分し、後でそれを文字列に再構成することができます。

$Version = $contents | ?{$_ -match 'AssemblyVersion\("(\d+)\.(\d+)\.\(d+)\.(\d+)"\)'}|%{ 
    [PSCustomObject]@{ 
     [int]'First'=$Matches[1] 
     [int]'Second'=$Matches[2] 
     [int]'Third'=$Matches[3] 
     [int]'Fourth'=$Matches[4] 
    } 
} 

次に、$Version.Third++と増分して3番目のセットを増やすことができます。それからちょうどそれをバック吐き出すためにフォーマットされた文字列を使用します。

'AssemblyVersion("{0}.{1}.{2}.{3}")' -f $Version.First, $Version.Second, $Version.Third, $Version.Fourth 

したいだけのようAssemblyVersion("1.0.21.1")を生成すること。

関連する問題