-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.build.ps1
137 lines (113 loc) · 4.7 KB
/
.build.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
<#
.Synopsis
Build script (https://github.com/nightroman/Invoke-Build)
.Description
How to use this script and build the module:
Get the utility script Invoke-Build.ps1:
https://github.com/nightroman/Invoke-Build
Copy it to the path. Set location to this directory. Build:
PS> Invoke-Build Build
This command builds the module and installs it to the $ModuleRoot which is
the working location of the module. The build fails if the module is
currently in use. Ensure it is not and then repeat.
The build task Help fails if the help builder Helps is not installed.
Ignore this or better get and use the script (it is really easy):
https://github.com/nightroman/Helps
#>
param
(
$Configuration = 'Release',
$logfile = $null
)
$project_name = "VolusionAccess"
$project_short_name = "Volusion"
# Folder structure:
# \build - Contains all code during the build process
# \build\artifacts - Contains all files during intermidiate bulid process
# \build\output - Contains the final result of the build process
# \release - Contains final release files for upload
# \release\archive - Contains files archived from the previous builds
# \src - Contains all source code
$build_dir = "$BuildRoot\build"
$log_dir = "$BuildRoot\log"
$build_artifacts_dir = "$build_dir\artifacts"
$build_output_dir = "$build_dir\output"
$release_dir = "$BuildRoot\release"
$archive_dir = "$release_dir\archive"
$src_dir = "$BuildRoot\src"
$solution_file = "$src_dir\$project_name.sln"
$nuget = "$src_dir\.nuget\NuGet.exe"
# Use MSBuild.
Set-Alias MSBuild16 (Join-Path -Path (Get-VSSetupInstance | Where-Object {$_.DisplayName -eq 'Visual Studio Professional 2019'} | select InstallationPath | Select-Object -first 1).InstallationPath -ChildPath "MSBuild\Current\Bin\MSBuild.exe")
task Clean {
exec { MSBuild16 "$solution_file" /t:Clean /p:Configuration=$configuration /v:quiet }
Remove-Item -force -recurse $build_dir -ErrorAction SilentlyContinue | Out-Null
}
task Init Clean, {
New-Item $build_dir -itemType directory | Out-Null
New-Item $build_artifacts_dir -itemType directory | Out-Null
New-Item $build_output_dir -itemType directory | Out-Null
}, NuGetRestore
task NuGetRestore {
& $nuget restore $solution_file
}
task Build {
exec { MSBuild16 "$solution_file" /t:Build /p:Configuration=$configuration /v:minimal /p:OutDir="$build_artifacts_dir\" }
}
task Package {
New-Item $build_output_dir\$project_name\lib\net45 -itemType directory -force | Out-Null
Copy-Item $build_artifacts_dir\$project_name.??? $build_output_dir\$project_name\lib\net45 -PassThru |% { Write-Host "Copied " $_.FullName }
}
# Set $script:Version = assembly version
task Version {
assert (( Get-Item $build_artifacts_dir\$project_name.dll ).VersionInfo.FileVersion -match '^(\d+\.\d+\.\d+)')
$script:Version = $matches[1]
}
task Archive {
New-Item $release_dir -ItemType directory -Force | Out-Null
New-Item $archive_dir -ItemType directory -Force | Out-Null
Move-Item -Path $release_dir\*.* -Destination $archive_dir
}
task Zip Version, {
$release_zip_file = "$release_dir\$project_name.$Version.zip"
$7z = Get-ChildItem -recurse $src_dir\packages -include 7za.exe | Sort-Object LastWriteTime -descending | Select-Object -First 1
Write-Host "Zipping release to: " $release_zip_file
exec { & $7z a $release_zip_file $build_output_dir\$project_name\lib\net45\* -mx9 }
}
task NuGet Package, Version, {
Write-Host ================= Preparing $project_name Nuget package =================
$text = "$project_short_name webservices API wrapper."
# nuspec
Set-Content $build_output_dir\$project_name\$project_name.nuspec @"
<?xml version="1.0"?>
<package>
<metadata>
<id>$project_name</id>
<version>$Version</version>
<authors>Slav Ivanyuk</authors>
<owners>Slav Ivanyuk</owners>
<projectUrl>https://github.com/agileharbor/$project_name</projectUrl>
<licenseUrl>https://raw.github.com/agileharbor/$project_name/master/License.txt</licenseUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<copyright>Copyright (C) Agile Harbor, LLC</copyright>
<summary>$text</summary>
<description>$text</description>
<tags>$project_short_name</tags>
<dependencies>
<group targetFramework="net45">
<dependency id="Netco" version="2.0.2" />
<dependency id="CuttingEdge.Conditions" version="1.2.0.0" />
</group>
</dependencies>
</metadata>
</package>
"@
# pack
exec { & $nuget pack $build_output_dir\$project_name\$project_name.nuspec -Output $build_dir }
$push_project = Read-Host "Push $($project_name) " $Version " to NuGet? (Y/N)"
Write-Host $push_project
if( $push_project -eq "y" -or $push_project -eq "Y" ) {
Get-ChildItem $build_dir\*.nupkg |% { exec { & $nuget push $_.FullName -Source nuget.org }}
}
}
task . Init, Build, Package, Zip, NuGet