forked from MarcosMeli/FileHelpers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.ps1
184 lines (134 loc) · 5.24 KB
/
default.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
Include("CurrentVersion.ps1")
properties {
$base_dir = resolve-path .
$package_dir = "$base_dir\..\packages"
$config = "Release"
}
#tasks ----------------------------------------------------------------------------
task default -depends pack
task version {
Update-AssemblyInfoFile '..\FileHelpers\VersionInfo.cs' ($AssemblyVersion+'.0') $FullCurrentVersion $VisibleVersion
Update-NuGetVersion '..\Build\NuGet\FileHelpers.ExcelStorage.nuspec' $VisibleVersion
Update-NuGetVersion '..\Build\NuGet\FileHelpers.ExcelNPOIStorage.nuspec' $VisibleVersion
Update-NuGetVersion '..\Build\NuGet\FileHelpers.nuspec' $VisibleVersion
}
function Update-AssemblyInfoFile ([string] $filename, [string] $assemblyVersionNumber, [string] $fileVersionNumber, [string] $informationalVersionNumber)
{
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$informationalVersionPattern = 'AssemblyInformationalVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$assemblyVersion = 'AssemblyVersion("' + $assemblyVersionNumber + '")';
$fileVersion = 'AssemblyFileVersion("' + $fileVersionNumber + '")';
$informationalVersion = 'AssemblyInformationalVersion("' + $informationalVersionNumber + '")';
Write-Host $filename
$filename + ' -> ' + $assemblyVersionNumber
(Get-Content $filename) | ForEach-Object {
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $fileVersionPattern, $fileVersion } |
% {$_ -replace $informationalVersionPattern, $informationalVersion }
} | Set-Content $filename
}
function Update-NuGetVersion ([string] $filename, [string] $versionNumber)
{
$versionPattern = '\<version\>[0-9]+(\.([0-9]+|\*)){1,3}\<\/version\>'
$version = '<version>' + $versionNumber + '</version>';
$dependenceVersionPattern = 'id="FileHelpers" version=\"[0-9]+(\.([0-9]+|\*)){1,3}\"'
$dependenceVersion = 'id="FileHelpers" version="' + $versionNumber + '"';
Write-Host $filename
$filename + ' -> ' + $assemblyVersionNumber
(Get-Content $filename) | ForEach-Object {
% {$_ -replace $versionPattern, $version } |
% {$_ -replace $dependenceVersionPattern, $dependenceVersion }
} | Set-Content $filename
}
task common -depends version {
"##teamcity[buildNumber '" + $VisibleVersion + "']"
Delete-Make-Directory ..\$config
Delete-Make-Directory "..\Output"
}
task compile -depends common {
"Compiling " + $config
Compile-Sln-With-Deploy "..\FileHelpers.OnlyLibs.sln" "4.5" "Lib\net45"
Compile-Sln-With-Deploy "..\FileHelpers.OnlyLibs.sln" "4.0" "Lib\net40"
Compile-Sln "..\FileHelpers.sln" "4.5"
$delFiles = "..\" + $config + "\*.config"
del $delFiles
Delete-Directory ..\$config\bin
}
task compiledebug -depends common {
$config = "Debug"
"Compiling Debug"
Compile-Sln "..\FileHelpers.sln" "4.5"
}
task docs -depends compile {
"Documenting"
exec { msbuild FileHelpers.shfbproj /p:Configuration=$config /nologo }
Make-Directory ..\$config\Docs
copy ..\Help\FileHelpers.chm ..\$config\Docs\FilHelpers.chm
}
task pack -depends compile, docs {
"Packing"
copy "Home Page.url" ..\$config\
$zipName = "Output\FileHelpers_" + $CurrentVersion + "_Build.zip"
Create-Zip $config $zipName
}
task test -depends compile{
"Testing"
New-Item $build_dir\local\artifacts -Type directory -Force > $null
cd $package_dir\xunit.runners*\tools\
exec { & .\xunit.console.clr4 $base_dir\tests.xunit }
}
#functions ----------------------------------------------------
function Delete-Make-Directory($path)
{
Delete-Directory $path
Make-Directory $path
}
function Delete-Directory($path)
{
rd $path -recurse -force -ErrorAction SilentlyContinue | out-null
}
function Make-Directory($path)
{
md $path -ErrorAction SilentlyContinue | out-null
}
function Compile-Sln($path, $targetFramework)
{
exec { msbuild $path /p:TargetFrameworkVersion=v$targetFramework /t:rebuild /p:Configuration=$config /nologo /verbosity:minimal }
}
function Compile-Sln-With-Deploy($path, $targetFramework, $deploy)
{
Compile-Sln $path $targetFramework
$deployDir = "..\" + $config + "\" + $deploy
Make-Directory $deployDir
$fromDir = "..\" + $config + "\Bin"
$fromFiles = $fromDir + "\*.*"
copy $fromFiles $deployDir
Delete-Directory $fromDir
}
function Get-AssemblyInformationalVersion($path)
{
$line = Get-Content $path | where {$_.Contains("AssemblyInformationalVersion")}
$line.Split('"')[1]
}
function Update-AssemblyInformationalVersion
{
if ($preReleaseVersion -ne $null)
{
$version = ([string]$input).Split('-')[0]
$date = Get-Date
$parsed = $preReleaseVersion.Replace("{date}", $date.ToString("yyMMdd"))
return "$version-$parsed"
}
else
{
return $input
}
}
function Create-Zip($sourcePath, $destinationFile)
{
cd $package_dir\SharpZipLib.*\lib\20\
Add-Type -Path ICSharpCode.SharpZipLib.dll
$zip = New-Object ICSharpCode.SharpZipLib.Zip.FastZip
$zip.CreateZip("$destinationFile", "$sourcePath", $true, $null)
}