-
Notifications
You must be signed in to change notification settings - Fork 6
/
AssemblyVersioning.ps1
60 lines (43 loc) · 1.52 KB
/
AssemblyVersioning.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
param (
[Parameter(Mandatory=$True)]
[string]$rootDir,
[Parameter(Mandatory=$True)]
[string]$fileNamePattern,
[Parameter(Mandatory=$True)]
[string]$major,
[Parameter(Mandatory=$True)]
[string]$minor
)
Write-Verbose 'Entering assemblyversioning.ps1'
### First, mount the assembly version ###
#Calculate today's julian date
function Get-JulianDate {
#Calculate today's julian date
$Year = get-date -format yy
$JulianYear = $Year.Substring(1)
$DayOfYear = (Get-Date).DayofYear
$JulianDate = $JulianYear + "{0:D3}" -f $DayOfYear
$JulianDate
return
}
$build = Get-JulianDate
$buildNumberFromVso = $($env:BUILD_BUILDNUMBER)
$revision = $buildNumberFromVso.Split(".")[1]
# The Assembly Version
$assemblyVersion = "$major.$minor.$build.$revision"
Write-Host "The version this build will generate is $assemblyVersion"
$assemblyVersionString = "AssemblyVersion(""$assemblyVersion"")"
$assemblyFileVersionString = "AssemblyFileVersion(""$assemblyVersion"")"
$assemblyInfoFiles = Get-ChildItem -Path $rootDir -Filter $fileNamePattern -Recurse
$fileCount = $assemblyInfoFiles.Count
Write-Host ""
Write-Host "Started writing the $fileNamePattern files..."
Write-Host ""
foreach($file in $assemblyInfoFiles){
$fullFilePath = Join-Path $file.Directory $file.Name
Write-Host "Editing $fullFilePath"
Add-Content -Path $fullFilePath -Value "`n[assembly: $assemblyVersionString]"
Add-Content -Path $fullFilePath -Value "[assembly: $assemblyFileVersionString]"
}
Write-Host ""
Write-Host "Finished editing $fileCount AssemblyInfo files."