/
SetVersionInAssemblyInfoCsFiles.ps1
43 lines (39 loc) · 1.34 KB
/
SetVersionInAssemblyInfoCsFiles.ps1
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
37
38
39
40
41
42
43
# Set version in AssemblyInfo.cs files.
Param (
[string]$rootFolder,
[string]$version,
[string]$filePattern = "AssemblyInfo.cs"
)
function UpdateAssemblyInfo()
{
foreach ($file in $input)
{
$path = $file.FullName
Write-Host ($path)
$isUpdated = $false
$patternAV = '^((?!\/\/).)*\[assembly: AssemblyVersion\("(.*)"\)\]'
$patternAFV = '^((?!\/\/).)*\[assembly: AssemblyFileVersion\("(.*)"\)\]'
(Get-Content $path) | ForEach-Object{
if($_ -match $patternAV){
# We have found the matching line
$isUpdated = $true
'[assembly: AssemblyVersion("{0}")]' -f $version
} elseif($_ -match $patternAFV){
$isUpdated = $true
# We have found the matching line
'[assembly: AssemblyFileVersion("{0}")]' -f $version
} else {
# Output line as is
$_
}
} | Set-Content $path
if (!$isUpdated) {
Write-Host ' Nothing found to update.'
}
}
}
Write-Host ("Root folder: " + $rootFolder)
Write-Host ("File pattern: " + $filePattern)
Write-Host ("Version: " + $version)
Write-Host ("Updating files...")
Get-Childitem -Path $rootFolder -recurse |? {$_.Name -like $filePattern} | UpdateAssemblyInfo;