Skip to content

Commit 60add65

Browse files
committed
Added Scripts/SetVersion.ps1 for bumping version of AssemblyInfo.cs and nuget .nuspec file.
1 parent 30301d7 commit 60add65

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

Scripts/SetVersion.ps1

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#-------------------------------------------------------------------------------
2+
# Description: Sets the AssemblyVersion and AssemblyFileVersion of
3+
# AssemblyInfo.cs files.
4+
# Author: Luis Rocha
5+
# Version: 1.0
6+
#-------------------------------------------------------------------------------
7+
8+
#-------------------------------------------------------------------------------
9+
# Displays how to use this script.
10+
#-------------------------------------------------------------------------------
11+
function Help {
12+
"Sets the AssemblyVersion and AssemblyFileVersion of AssemblyInfo.cs files`n"
13+
".\SetVersion.ps1 [VersionNumber]`n"
14+
" [VersionNumber] The version number to set, for example: 1.1.9301.0"
15+
" If not provided, a version number will be generated.`n"
16+
}
17+
18+
#-------------------------------------------------------------------------------
19+
# Generate a version number.
20+
# Note: customize this function to generate it using your version schema.
21+
#-------------------------------------------------------------------------------
22+
function Generate-VersionNumber {
23+
$today = Get-Date
24+
return "1.0." + ( ($today.year - 2000) * 1000 + $today.DayOfYear )+ ".0"
25+
}
26+
27+
#-------------------------------------------------------------------------------
28+
# Update version numbers of AssemblyInfo.cs
29+
#-------------------------------------------------------------------------------
30+
function Update-AssemblyInfoFiles ([string] $version) {
31+
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
32+
$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
33+
$assemblyVersion = 'AssemblyVersion("' + $version + '")';
34+
$fileVersion = 'AssemblyFileVersion("' + $version + '")';
35+
36+
Get-ChildItem ..\ -r | Where { $_.PSChildName -match "^AssemblyInfo\.cs$"} | ForEach-Object {
37+
$filename = $_.Directory.ToString() + '\' + $_.Name
38+
$filename + ' -> ' + $version
39+
40+
# If you are using a source control that requires to check-out files before
41+
# modifying them, make sure to check-out the file here.
42+
# For example, TFS will require the following command:
43+
# tf checkout $filename
44+
45+
(Get-Content $filename -Encoding UTF8) | ForEach-Object {
46+
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
47+
% {$_ -replace $fileVersionPattern, $fileVersion }
48+
} | Set-Content $filename -Encoding UTF8
49+
}
50+
}
51+
52+
#-------------------------------------------------------------------------------
53+
# Update version numbers of UnitsNet.nuspec
54+
#-------------------------------------------------------------------------------
55+
function Update-NuspecFiles ([string] $version) {
56+
$nugetVersionPattern = '<version>.*?</version>';
57+
$nugetVersion = '<version>'+$version+'</version>';
58+
59+
Get-ChildItem ..\ -r | Where { $_.PSChildName -match "^UnitsNet\.nuspec$"} | ForEach-Object {
60+
$filename = $_.Directory.ToString() + '\' + $_.Name
61+
$filename + ' -> ' + $version
62+
63+
# If you are using a source control that requires to check-out files before
64+
# modifying them, make sure to check-out the file here.
65+
# For example, TFS will require the following command:
66+
# tf checkout $filename
67+
68+
(Get-Content $filename -Encoding UTF8) | ForEach-Object {
69+
% {$_ -replace $nugetVersionPattern, $nugetVersion }
70+
} | Set-Content $filename -Encoding UTF8
71+
}
72+
}
73+
74+
#-------------------------------------------------------------------------------
75+
# Parse arguments.
76+
#-------------------------------------------------------------------------------
77+
$version = $args[0]
78+
while ($version -notmatch "[0-9]+(\.([0-9]+|\*)){1,3}") {
79+
if ($version -eq '/?') {
80+
Help
81+
}
82+
else {
83+
"About to update the version of nuget package .nuspec and AssemblyInfo.cs files."
84+
$version = Read-Host 'Enter new version'
85+
}
86+
}
87+
88+
Update-AssemblyInfoFiles $version
89+
Update-NuspecFiles $version
90+
91+

0 commit comments

Comments
 (0)