-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdefault.ps1
148 lines (114 loc) · 4.5 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
properties {
$TargetFramework = "net-4.0"
$DownloadDependentPackages = $true
$UploadPackage = $false
$NugetKey = ""
}
$baseDir = resolve-path .
$releaseRoot = "$baseDir\Release"
$releaseDir = "$releaseRoot\net40"
$buildBase = "$baseDir\build"
$sourceDir = "$baseDir"
$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.1.0.4"
include $toolsDir\psake\buildutils.ps1
task default -depends ReleaseXmlTransformer
task Clean {
delete-directory $binariesDir
}
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 "$sourceDir\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 = "XmlTransformer.sln"
exec { &$script:msBuild $solutionFile /p:OutDir="$buildBase\" }
$assemblies = @()
$assemblies += dir $buildBase\*.exe
$assemblies += dir $buildBase\*.dll -Exclude **Tests.dll
& $ilMergeTool /lib:$baseDir /t:exe /out:"$binariesDir\XmlTransformer.exe" /targetplatform:$script:ilmergeTargetFramework /log:"$buildBase\MergeLog.txt" $assemblies
$mergeLogContent = Get-Content "$buildBase\MergeLog.txt"
echo "------------------------------Merge Log-----------------------"
echo $mergeLogContent
}
task PrepareRelease -depends CompileMain {
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"
}
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 = "XmlTransformer"
$packit.package_description = "Merges XML configuration files the way NuGet does it or Transforms them the way Microsofts web.config transformations does it but without the dependency on MSBuild."
invoke-packit $packageName $script:packageVersion @{} "binaries\XmlTransformer.exe" @{}
remove-module packit
}
task ReleaseXmlTransformer -depends CreatePackages {
}