-
Notifications
You must be signed in to change notification settings - Fork 6
/
SetVersion.ps1
38 lines (30 loc) · 1.07 KB
/
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
param([Parameter(Mandatory=$true)][string]$version)
function Set-CsprojVersionWithPattern
{
Param([string]$version, [string]$path, [string]$pattern, [string]$element, [bool]$four=$false)
(Get-Content $path) | ForEach-Object {
if (!($_.ToString().StartsWith('//')) -and ($_ -match $pattern))
{
$prefix = $_.ToString().Substring(0, $_.ToString().IndexOf($matches[0]))
if ($four)
{
($prefix + '<' + $element + '>' + $version + '.0' + '</' + $element + '>')
}
else
{
($prefix + '<' + $element + '>' + $version + '</' + $element + '>')
}
}
else
{
# Output line as is
$_
}
} | Set-Content $path
}
function Set-CsprojVersion
{
Param([string]$version, [string]$path)
Set-CsprojVersionWithPattern -version $version -path $path -element 'Version' -pattern '\<Version\>(.*)\<\/Version\>'
}
Set-CsprojVersion -version $version -path (Join-Path $pwd 'Source/HtmlTextWriter/HtmlTextWriter.csproj')