-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault.ps1
164 lines (126 loc) · 6.33 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
# required parameters :
# $databaseName
properties {
$visualstudioversion = null-coalesce $visualstudioversion "12.0"
$projectName = "DTMF"
$version = null-coalesce $version ("1.1." + (get-date -format "yyyy")) #changed to three numbers since that's how version comes from teamcity
$fullversion = $version + "." + (get-date -format "MMdd")
$projectConfig = "Release"
$base_dir = resolve-path .
$source_dir = "$base_dir\source"
$webapp_dir = "$source_dir\$projectName.Website"
$zipPath = "$base_dir\lib\7zip\7za.exe"
$build_dir = null-coalesce $build_dir "$base_dir\build"
$package_dir = "$build_dir\Latest"
$package_file = "$build_dir\" + $projectName + "-" + $version +"_package.zip"
}
task default -depends Init, Compile
task ci -depends Init, Compile, Package
task Init {
#delete the build directories, but leave any artifacts at the root then put it back
delete_directory "$build_dir"
create_directory "$build_dir"
}
task Compile -depends Init {
write-host "Restore solution-level nuget packages"
exec { & $source_dir\.nuget\nuget.exe restore $source_dir\$projectName.sln }
Update-AssemblyInfoFiles $fullversion
msbuild /t:clean /v:q /nologo /p:Configuration=$projectConfig $source_dir\$projectName.sln /p:VisualStudioVersion=$visualstudioversion
msbuild /t:build /v:q /nologo /p:Configuration=$projectConfig $source_dir\$projectName.sln /p:VisualStudioVersion=$visualstudioversion
#moves all .nupkg in $source_dir and not in packages folder to $build_dir
Get-ChildItem -Path $source_dir\*.nupkg -Recurse | Where-Object { $_.FullName -notmatch '\\packages($|\\)' } | Move-Item -Destination $build_dir -Force
copy_website_files "$webapp_dir" "$package_dir\web"
Update-AssemblyInfoFiles ($version.Replace($version.Split('.')[-1], "0") + ".0") #cleans the version's year to something like 3.0.0.0
}
task Package -depends Compile {
write-host "Clean package directory"
delete_directory $package_dir
write-host "Copy web app"
copy_website_files "$webapp_dir" "$package_dir\web"
write-host "Zip it up"
zip_directory $package_dir $package_file
}
function global:zip_directory($directory,$file) {
write-host "Zipping folder: " $test_assembly
delete_file $file
cd $directory
& "$zipPath" a -mx=9 -r $file
cd $base_dir
}
function global:copy_website_files($source,$destination){
$exclude = @('*.user','*.dtd','*.tt','*.cs','*.csproj','*.vb','*.vbproj','*.orig', '*.log')
copy_files $source $destination $exclude
delete_directory "$destination\obj"
while (Get-ChildItem $destination -recurse | where {!@(Get-ChildItem -force $_.fullname)} | Test-Path) {
Get-ChildItem $destination -recurse | where {!@(Get-ChildItem -force $_.fullname)} | Remove-Item
}
}
function global:copy_files($source,$destination,$exclude=@()){
create_directory $destination
Get-ChildItem $source -Recurse -Exclude $exclude -ErrorAction SilentlyContinue | Copy-Item -ErrorAction SilentlyContinue -Destination {Join-Path $destination $_.FullName.Substring($source.length)}
}
function global:Copy_and_flatten ($source,$filter,$dest) {
ls "$source" -filter "$filter" -r | Where-Object{!$_.FullName.Contains("$testCopyIgnorePath") -and !$_.FullName.Contains("packages") }| cp -dest "$dest" -force
}
function global:copy_all_assemblies_for_test($destination){
create_directory "$destination"
Copy_and_flatten "$source_dir" *.exe "$destination"
Copy_and_flatten "$source_dir" *.dll "$destination"
Copy_and_flatten "$source_dir" *.config "$destination"
Copy_and_flatten "$source_dir" *.xml "$destination"
Copy_and_flatten "$source_dir" *.pdb "$destination"
#Copy_and_flatten $source_dir *.sql $destination
}
function global:delete_file($file) {
if($file) { remove-item $file -force -ErrorAction SilentlyContinue | out-null }
}
function global:delete_directory($directory_name)
{
rd $directory_name -recurse -force -ErrorAction SilentlyContinue | out-null
}
function global:delete_files_in_dir($dir)
{
get-childitem $dir -recurse | foreach ($_) {remove-item $_.fullname}
}
function global:create_directory($directory_name)
{
mkdir $directory_name -ErrorAction SilentlyContinue | out-null
}
function Update-AssemblyInfoFiles ([string] $version, [System.Array] $excludes = $null) {
#-------------------------------------------------------------------------------
# Update version numbers of AssemblyInfo.cs
# adapted from: http://www.luisrocha.net/2009/11/setting-assembly-version-with-windows.html
#-------------------------------------------------------------------------------
if ($version -notmatch "[0-9]+(\.([0-9]+|\*)){1,3}") {
Write-Error "Version number incorrect format: $version"
}
$versionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$versionAssembly = 'AssemblyVersion("' + $version + '")';
$versionFilePattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$versionAssemblyFile = 'AssemblyFileVersion("' + $version + '")';
Get-ChildItem -r -filter AssemblyInfo.* | % {
$filename = $_.fullname
$update_assembly_and_file = $true
# set an exclude flag where only AssemblyFileVersion is set
if ($excludes -ne $null)
{ $excludes | % { if ($filename -match $_) { $update_assembly_and_file = $false } } }
# see http://stackoverflow.com/questions/3057673/powershell-locking-file
# I am getting really funky locking issues.
# The code block below should be:
# (get-content $filename) | % {$_ -replace $versionPattern, $version } | set-content $filename
$tmp = ($file + ".tmp")
if (test-path ($tmp)) { remove-item $tmp }
if ($update_assembly_and_file) {
(get-content $filename) | % {$_ -replace $versionFilePattern, $versionAssemblyFile } | % {$_ -replace $versionPattern, $versionAssembly } > $tmp
write-host Updating file AssemblyInfo and AssemblyFileInfo: $filename --> $versionAssembly / $versionAssemblyFile
} else {
(get-content $filename) | % {$_ -replace $versionFilePattern, $versionAssemblyFile } > $tmp
write-host Updating file AssemblyInfo only: $filename --> $versionAssemblyFile
}
if (test-path ($filename)) { remove-item $filename }
#diff tools aren't too happy with Unicode files - change it to ansi
Set-Content $tmp -Encoding ASCII -Value (Get-Content $tmp)
move-item $tmp $filename -force
}
}
function null-coalesce($a, $b) { if ($a -ne $null) { $a } else { $b } }