This repository has been archived by the owner on Sep 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildScript.ps1
113 lines (98 loc) · 4.62 KB
/
BuildScript.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
$psake.use_exit_on_error = $true
properties {
$currentDir = resolve-path .
$baseDir = $psake.build_script_dir
$configuration = "debug"
$filesDir = "$baseDir\BuildFiles"
$version = "1.0." + (hg log -r "last(tagged())::" --template '{rev}:{node}\n' | measure-object).Count
$nugetDir = "$baseDir\.NuGet"
}
task Debug -depends Default
task Default -depends Clean-Solution, Build-Solution, Test-Solution
task Download -depends Clean-Solution, Update-AssemblyInfoFiles, Build-Output
task Test-Solution -depends Build-Solution {
$runnerDir = ([array](dir $baseDir\packages\xunit.runners.*))[-1];
exec { .$runnerDir\tools\xunit.console.clr4.exe "nquant.Facts\bin\$configuration\nquant.Facts.dll" }
}
task Build-35-Solution {
$conf = $configuration+35
exec { msbuild 'nquant.core\nquant.core.csproj' /maxcpucount /t:Build /v:Minimal /p:Configuration=$conf }
exec { msbuild 'nquantshell\nquant.csproj' /maxcpucount /t:Build /v:Minimal /p:Configuration=$conf }
}
task Clean-Solution -depends Clean-BuildFiles {
$conf = $configuration+35
clean $baseDir\nquant.core\Nuget\Lib
create $baseDir\nquant.core\Nuget\Lib
exec { msbuild nQuant.sln /t:Clean /v:quiet }
exec { msbuild 'nQuant.core\nquant.core.csproj' /t:Clean /v:quiet /p:Configuration=$conf }
exec { msbuild 'nQuantShell\nQuant.csproj' /t:Clean /v:quiet /p:Configuration=$conf }
}
task Update-AssemblyInfoFiles {
$commit = hg log --template '{rev}:{node}\n' -l 1
Update-AssemblyInfoFiles $version $commit
}
task Build-Solution -depends Build-35-Solution {
exec { msbuild nQuant.sln /maxcpucount /t:Build /v:Minimal /p:Configuration=$configuration }
}
task Clean-BuildFiles {
clean $filesDir
}
task Push-Nuget {
$pkg = Get-Item -path $filesDir/nquant.0.*.*.nupkg
exec { .$nugetDir\nuget.exe push $filesDir\$($pkg.Name) }
}
task Build-Output -depends Build-Solution {
clean $baseDir\nquant.core\Nuget\Lib
create $baseDir\nquant.core\Nuget\Lib\net20
create $baseDir\nquant.core\Nuget\Lib\net40
Copy-Item $baseDir\nquant.core\bin\v3.5\$configuration\*.* $baseDir\nquant.core\Nuget\Lib\net20
Copy-Item $baseDir\nquant.core\bin\v4.0\$configuration\*.* $baseDir\nquant.core\Nuget\Lib\net40
clean $baseDir\nquant.core\Nuget\Tools
create $baseDir\nquant.core\Nuget\Tools\net20
create $baseDir\nquant.core\Nuget\Tools\net40
Copy-Item $baseDir\nquantShell\bin\v3.5\$configuration\*.* $baseDir\nquant.core\Nuget\Tools\net20
Copy-Item $baseDir\nquantShell\bin\v4.0\$configuration\*.* $baseDir\nquant.core\Nuget\Tools\net40
clean $filesDir
create $filesDir
create $filesDir\net35
create $filesDir\net40
Copy-Item $baseDir\nquantShell\bin\v3.5\$configuration\*.* $filesDir\net35
Copy-Item $baseDir\nquantShell\bin\v4.0\$configuration\*.* $filesDir\net40
Copy-Item $baseDir\License.txt $filesDir
cd $filesDir
exec { ..\Tools\zip.exe -9 -r nQuant-$version.zip . }
cd $currentDir
exec { .$nugetDir\nuget.exe pack "nQuant.core\Nuget\nQuant.nuspec" -o $filesDir -version $version }
}
function clean($path) {
remove-item -force -recurse $path -ErrorAction SilentlyContinue
}
function create([string[]]$paths) {
foreach ($path in $paths) {
if ((test-path $path) -eq $FALSE) {
new-item -path $path -type directory | out-null
}
}
}
# Borrowed from Luis Rocha's Blog (http://www.luisrocha.net/2009/11/setting-assembly-version-with-windows.html)
function Update-AssemblyInfoFiles ([string] $version, [string] $commit) {
$assemblyVersionPattern = 'AssemblyVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileVersionPattern = 'AssemblyFileVersion\("[0-9]+(\.([0-9]+|\*)){1,3}"\)'
$fileCommitPattern = 'AssemblyTrademarkAttribute\("[0-9]+:[a-f0-9]{40}"\)'
$assemblyVersion = 'AssemblyVersion("' + $version + '")';
$fileVersion = 'AssemblyFileVersion("' + $version + '")';
$commitVersion = 'AssemblyTrademarkAttribute("' + $commit + '")';
Get-ChildItem -path $baseDir -r -filter AssemblyInfo.cs | ForEach-Object {
$filename = $_.Directory.ToString() + '\' + $_.Name
$filename + ' -> ' + $version
# If you are using a source control that requires to check-out files before
# modifying them, make sure to check-out the file here.
# For example, TFS will require the following command:
# tf checkout $filename
(Get-Content $filename) | ForEach-Object {
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $fileVersionPattern, $fileVersion } |
% {$_ -replace $fileCommitPattern, $commitVersion }
} | Set-Content $filename
}
}