- Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathCore-SetVersion.ps1
73 lines (55 loc) · 2.06 KB
/
Core-SetVersion.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
61
62
63
64
65
66
67
68
69
70
71
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$buildNumber
)
$VersionRegex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
if($buildNumber-match$VersionRegEx){
Write-Output"Parsed Date From Build: $dateFromBuildNumber"
$revision= [int]::Parse($matches[4]).ToString()
$versionNumber= [int]::Parse($matches[1]).ToString() +"."+ [int]::Parse($matches[2]).ToString() +"."+ [int]::Parse($matches[3]).ToString() +"."+$revision
Write-Host"Version Number"$versionNumber
}
else{
throw"Build format does not match the expected pattern (buildName_w.x.y.z)"
}
## APPLY VERSION TO ASSEMBLY FILES (AssemblyVersion and AssemblyFileVersion)
Write-Host
Write-Host"Applying version to AssemblyInfo files"
$files=Get-ChildItem-include "*AssemblyInfo.cs"-Recurse |Where-Object{ $_.FullName-match"CoreTemplateStudio" }
if($files)
{
Write-Host"Will apply $versionNumber to $($files.count) files."
$assemblyVersionRegEx="\(""$VersionRegex""\)"
$assemblyVersionReplacement="(""$versionNumber"")"
foreach ($filein$files) {
$filecontent=Get-Content($file)
attrib $file-r
$filecontent-replace$assemblyVersionRegEx,$assemblyVersionReplacement|Out-File$file utf8
Write-Host"$file - version applied"
}
}
else
{
Write-Warning"No files found to apply version."
}
## APPLY VERSION TO PROJ FILES
Write-Host
Write-Host"Applying version to csproj files"
$files=Get-ChildItem-include "*.csproj"-Recurse |Where-Object{ $_.FullName-match"CoreTemplateStudio" }
if($files)
{
Write-Host"Will apply $versionNumber to $($files.count) files."
$csprojVersionRegEx="(<Version>)$VersionRegex(</Version>)"
$csprojVersionReplacement="<Version>$versionNumber</Version>"
foreach ($filein$files) {
$filecontent=Get-Content($file)
attrib $file-r
$filecontent-replace$csprojVersionRegEx,$csprojVersionReplacement|Out-File$file utf8
Write-Host"$file - version applied"
}
}
else
{
Write-Warning"No files found to apply version."
}