-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathversion-assemblyinfo
37 lines (30 loc) · 1.61 KB
/
version-assemblyinfo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$directoryPath = Split-Path ((Get-Variable MyInvocation).Value).MyCommand.Path # directory the script is running from (document root)
$assemblyFile = "$directoryPath\src\My Project\AssemblyInfo.vb" # AssemblyInfo file path
# Function which changes the AssemblyInfo.cs file with the current version
# found at: http://restoncode.azurewebsites.net/blog/2012/12/03/change-assembly-version-with-powershell/
# modified to have a stricter regex.
function ChangeAssemblyInfo {
$RegularExpression = [regex] '\<Assembly\:\ AssemblyVersionAttribute\(\"\d+\.\d+\.\d+\.\*\"\)\>'
# Get the Content of the file and store it in the variable
$fileContent = Get-Content $assemblyFile
Clear-Content $assemblyFile
foreach($content in $fileContent)
{
$value=$content -match $RegularExpression
if($value -eq $true) {
"'"+$content+"'" -match "(\d+).(\d+).(\d+).(\*)"
$majorVersion=$matches[1] -as [int]
$minorVersion=$matches[2] -as [int]
$buildNumer=$matches[3] -as [int]
$buildNumer= $buildNumer+1
Write-Host "updating build number to $buildNumberclear"
$replacedVersion=$content -replace "(\d+).(\d+).(\d+).(\*)","$majorVersion.$minorVersion.$buildNumer.*"
Add-Content $assemblyFile $replacedVersion
} else {
Add-Content $assemblyFile $content
}
}
Add-Content $assemblyFile "' Build revision on $currentDate by $currentUser"
}
# Run the function
ChangeAssemblyInfo