forked from DinoChiesa/DotNetZip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetVersion.ps1
151 lines (125 loc) · 4.23 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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# -------------------------------------------------------
# SetVersion.ps1
#
# Set the version in all the AssemblyInfo.cs or AssemblyInfo.vb files in
# any subdirectory. Also set the version in the Product.wxs file, in
# any subdirectory.
#
# usage:
# from cmd.exe:
# powershell.exe SetVersion.ps1 2.8.3.0
#
# from powershell.exe prompt:
# .\SetVersion.ps1 2.8.3.0
#
#
# This script is part of DotNetZip.
# DotNetZip is Copyright 2008-2011 Dino Chiesa.
#
# DotNetZip is licensed under the MS-PL. See the accompanying
# License.txt file.
#
# Last Updated: <2011-August-02 19:51:41>
#
# -------------------------------------------------------
function Usage
{
echo "Usage: ";
echo " from cmd.exe: ";
echo " powershell.exe SetVersion.ps1 2.8.3.0";
echo " ";
echo " from powershell.exe prompt: ";
echo " .\SetVersion.ps1 2.8.3.0";
echo " ";
}
function Update-SourceVersion
{
Param ([string]$Version)
$NewVersion = 'AssemblyVersion("' + $Version + '")';
$NewFileVersion = 'AssemblyFileVersion("' + $Version + '")';
foreach ($o in $input)
{
$av = select-string AssemblyVersion $o
$fv = select-string AssemblyVersion $o
if ($av -ne $null -or $fv -ne $null)
{
Write-output $o.FullName
if ($o.Attributes -band [System.IO.FileAttributes]::ReadOnly)
{
# checkout the file for edit, using the tf.exe tool, and
# passing the CodePlex authn info on cmd line.
c:\vs2010\common7\IDE\tf.exe edit $o.FullName $env:cplogin
if (-not $?)
{
Write-output " --> The TF checkout failed. "
# See exit code in $LASTEXITCODE
exit
}
}
$TmpFile = $o.FullName + ".tmp"
get-content $o.FullName |
%{$_ -replace 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewVersion } |
%{$_ -replace 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)', $NewFileVersion } > $TmpFile
move-item $TmpFile $o.FullName -force
}
}
}
function Update-SourceWxsVersion
{
Param ([string]$Version)
$NewVersion = 'productVersion = "' + $Version + '"';
foreach ($o in $input)
{
$pv = select-string productVersion $o
if ($pv -ne $null)
{
Write-output $o.FullName
if ($o.Attributes -band [System.IO.FileAttributes]::ReadOnly)
{
# checkout the file for edit, using the tf.exe tool, and
# passing the CodePlex authn info on cmd line
c:\vs2010\common7\IDE\tf edit $o.FullName $env:cplogin
if (-not $?)
{
Write-output " --> The TF checkout failed. "
# See exit code in $LASTEXITCODE
exit
}
}
$TmpFile = $o.FullName + ".tmp"
$newGuid = 'productId = "'+ [System.Guid]::NewGuid().ToString() + '"'
get-content $o.FullName |
%{$_ -replace 'productVersion *= *"[1-9]+(\.([0-9]+|\*)){1,3}"', $NewVersion } |
%{$_ -replace 'productId *= *"([0-9A-Fa-f]){8}-([0-9A-Fa-f]){4}-([0-9A-Fa-f]){4}-([0-9A-Fa-f]){4}-([0-9A-Fa-f]){12}"', $newGuid } > $TmpFile
move-item $TmpFile $o.FullName -force
}
}
}
function Update-AllAssemblyInfoFiles ( $version )
{
foreach ($file in "SolutionInfo.cs", "AssemblyInfo.cs", "AssemblyInfo.vb" )
{
get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceVersion $version ;
}
}
function Update-AllProductWxsFiles ( $version )
{
foreach ($file in "Product.wxs", "ComRegistration.wxs" )
{
get-childitem -recurse |? {$_.Name -eq $file} | Update-SourceWxsVersion $version ;
}
}
# validate arguments
$r= [System.Text.RegularExpressions.Regex]::Match($args[0], "^[0-9]+(\.[0-9]+){1,3}$");
if ($r.Success)
{
Update-AllAssemblyInfoFiles $args[0];
Update-AllProductWxsFiles $args[0];
}
else
{
echo " ";
echo "Bad Input!"
echo " ";
Usage ;
}