This repository has been archived by the owner on Dec 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
/
default.ps1
201 lines (155 loc) · 5.96 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
properties {
$ProductVersion = "1.0"
$BuildNumber = "0";
$PatchVersion = "2"
$TargetFramework = "net-4.0"
$DownloadDependentPackages = $true
$UploadPackage = $false
$NugetKey = ""
$PackageVersion = $null
}
$baseDir = resolve-path .
$releaseRoot = "$baseDir\Release"
$releaseDir = "$releaseRoot\net40"
$buildBase = "$baseDir\build"
$sourceDir = "$baseDir\src"
$samplesDir = "$baseDir\samples"
$outDir = "$buildBase\output"
$toolsDir = "$baseDir\tools"
$binariesDir = "$baseDir\binaries"
$ilMergeTool = "$toolsDir\ILMerge\ILMerge.exe"
$nugetExec = "$toolsDir\NuGet\NuGet.exe"
$script:msBuild = ""
$script:isEnvironmentInitialized = $false
$script:ilmergeTargetFramework = ""
$script:msBuildTargetFramework = ""
$script:packageVersion = "1.0.0"
$nunitexec = "tools\nunit\nunit-console.exe"
$script:nunitTargetFramework = "/framework=4.0";
include $toolsDir\psake\buildutils.ps1
task default -depends ReleaseOAuth
task Clean {
delete-directory $binariesDir -ErrorAction silentlycontinue
}
task Init -depends Clean {
create-directory $binariesDir
}
task DetectOperatingSystemArchitecture {
$isWow64 = ((Get-WmiObject -class "Win32_Processor" -property "AddressWidth").AddressWidth -eq 64)
if ($isWow64 -eq $true)
{
$script:architecture = "x64"
}
echo "Machine Architecture is $script:architecture"
}
task InstallDependentPackages {
cd "$baseDir\packages"
$files = dir -Exclude *.config
cd $baseDir
$installDependentPackages = $DownloadDependentPackages;
if($installDependentPackages -eq $false){
$installDependentPackages = ((($files -ne $null) -and ($files.count -gt 0)) -eq $false)
}
if($installDependentPackages){
dir -recurse -include ('packages.config') |ForEach-Object {
$packageconfig = [io.path]::Combine($_.directory,$_.name)
write-host $packageconfig
exec{ &$nugetExec install $packageconfig -o packages }
}
}
}
task InitEnvironment -depends DetectOperatingSystemArchitecture {
if($script:isEnvironmentInitialized -ne $true){
if ($TargetFramework -eq "net-4.0"){
$netfxInstallroot =""
$netfxInstallroot = Get-RegistryValue 'HKLM:\SOFTWARE\Microsoft\.NETFramework\' 'InstallRoot'
$netfxCurrent = $netfxInstallroot + "v4.0.30319"
$script:msBuild = $netfxCurrent + "\msbuild.exe"
echo ".Net 4.0 build requested - $script:msBuild"
$programFilesPath = (gc env:ProgramFiles)
if($script:architecture -eq "x64") {
$programFilesPath = (gc env:"ProgramFiles(x86)")
}
$frameworkPath = Join-Path $programFilesPath "Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0"
$script:ilmergeTargetFramework = "v4,$frameworkPath"
$script:msBuildTargetFramework ="/p:TargetFrameworkVersion=v4.0 /ToolsVersion:4.0"
$script:nunitTargetFramework = "/framework=4.0";
$script:isEnvironmentInitialized = $true
}
}
}
task CompileMain -depends InstallDependentPackages, InitEnvironment, Init {
$solutionFile = "$sourceDir\OAuth.sln"
exec { &$script:msBuild $solutionFile /p:OutDir="$buildBase\" }
$assemblies = @()
$assemblies += dir $buildBase\OAuth2Provider.dll
$assemblies += dir $buildBase\newtonsoft.json.dll
$assemblies += dir $buildBase\log4net.dll
& $ilMergeTool /lib:$baseDir /t:library /out:"$binariesDir\OAuth2Provider.dll" /internalize /targetplatform:$script:ilmergeTargetFramework /log:"$buildBase\MergeLog.txt" $assemblies
$mergeLogContent = Get-Content "$buildBase\MergeLog.txt"
echo "------------------------------Merge Log-----------------------"
echo $mergeLogContent
}
task TestMain -depends CompileMain {
if((Test-Path -Path $buildBase\test-reports) -eq $false){
Create-Directory $buildBase\test-reports
}
$testAssemblies = @()
$testAssemblies += dir $buildBase\*Tests.dll
exec {&$nunitexec $testAssemblies $script:nunitTargetFramework}
}
task CompileSamples -depends InstallDependentPackages, InitEnvironment, Init {
$solutionFile = "$samplesDir\Samples.sln"
exec { &$script:msBuild $solutionFile }
}
task PrepareRelease {
if((Test-Path $releaseRoot) -eq $true){
Delete-Directory $releaseRoot
}
Create-Directory $releaseRoot
if ($TargetFramework -eq "net-4.0"){
$releaseDir = "$releaseRoot\net40"
}
Create-Directory $releaseDir
Copy-Item -Force -Recurse "$baseDir\binaries" $releaseDir\binaries -ErrorAction SilentlyContinue
}
task CreatePackages -depends PrepareRelease {
if(($UploadPackage) -and ($NugetKey -eq "")){
throw "Could not find the NuGet access key Package Cannot be uploaded without access key"
}
$script:packageVersion = $PackageVersion
import-module $toolsDir\NuGet\packit.psm1
Write-Output "Loading the module for packing.............."
$packit.push_to_nuget = $UploadPackage
$packit.nugetKey = $NugetKey
$packit.framework_Isolated_Binaries_Loc = "$baseDir\release"
$packit.PackagingArtifactsRoot = "$baseDir\release\PackagingArtifacts"
$packit.packageOutPutDir = "$baseDir\release\packages"
$packit.targeted_Frameworks = "net40";
$packageName = "OAuth2Provider"
$packit.package_description = "OAuth 2 Provider"
invoke-packit $packageName $script:packageVersion @{} @("binaries\OAuth2Provider.dll","binaries\OAuth2Provider.pdb") @{}
remove-module packit
}
task GenerateAssemblyInfo {
if($env:BUILD_NUMBER -ne $null) {
$BuildNumber = $env:BUILD_NUMBER
}
Write-Output "Build Number: $BuildNumber"
$asmVersion = $ProductVersion + "." + $PatchVersion + "." + $BuildNumber
$PackageVersion = $asmVersion
Write-Output "##teamcity[buildNumber '$asmVersion']"
$asmInfo = "using System;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Security;
using System.Runtime.CompilerServices;
[assembly: AssemblyCompany(""Micah Martin"")]
[assembly: AssemblyFileVersion(""$asmVersion"")]
[assembly: AssemblyVersion(""$asmVersion"")]
[assembly: ComVisible(false)]
"
sc -Path "$baseDir\SharedAssemblyInfo.cs" -Value $asmInfo
}
task ReleaseOAuth -depends CompileMain, TestMain, CreatePackages, CompileSamples
task CompileAll -depends GenerateAssemblyInfo, CompileMain, TestMain, CompileSamples