-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.ps1
91 lines (73 loc) · 2.49 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
Function Info($msg) {
Write-Host -ForegroundColor DarkGreen "`nINFO: $msg`n"
}
Function Error($msg) {
Write-Host `n`n
Write-Error $msg
exit 1
}
Function CheckReturnCodeOfPreviousCommand($msg) {
if(-Not $?) {
Error "${msg}. Error code: $LastExitCode"
}
}
Function FindMsBuild() {
$vswhereCommand = Get-Command -Name "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
$msbuild = `
& $vswhereCommand `
-latest `
-requires Microsoft.Component.MSBuild `
-find MSBuild\**\Bin\MSBuild.exe `
| select-object -first 1
if(!$msbuild)
{
Error "Can't find MsBuild"
}
Info "MsBuild found: `n $msbuild"
return $msbuild
}
Function CreateZipArchive($fileFullName, $archiveFullName) {
Info "Create zip archive `n $archiveFullName from `n $fileFullName"
Compress-Archive -Force -Path $fileFullName -DestinationPath $archiveFullName
}
Function CopyFile($file, $dstFolder) {
Info "Copy `n '$file' to `n '$dstFolder'"
New-Item -Force -ItemType "directory" $dstFolder > $null
Copy-Item -Force -Path $file -Destination $dstFolder > $null
}
Function GetVersion() {
$gitCommand = Get-Command -Name git
$commitTag = & $gitCommand describe --exact-match --tags HEAD
if(-Not $?) {
Info "The commit is not tagged. Use 'v0.0-dev' as a tag instead"
$commitTag = "v0.0-dev"
}
$commitHash = & $gitCommand rev-parse --short HEAD
CheckReturnCodeOfPreviousCommand "Failed to get git commit hash"
return "$($commitTag.Substring(1))-$commitHash"
}
Function GetInstallerVersion($version) {
return $version.Split("-")[0];
}
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$root = Resolve-Path $PSScriptRoot
$publishDir = "$root/build/Release"
$projectName = "CoffeeBean"
$version = GetVersion
$installerVersion = GetInstallerVersion $version
$msbuild = FindMsBuild
Info "Version: '$version'. InstallerVersion: '$installerVersion'"
Info "Build project"
& $msbuild `
/property:RestorePackagesConfig=true `
/property:MSBuildWarningsAsMessages=NU1503 `
/property:Configuration=Release `
/property:DebugType=None `
/property:Version=$version `
/property:InstallerVersion=$installerVersion `
/target:"restore;build" `
$root/$projectName.sln
CheckReturnCodeOfPreviousCommand "build failed"
CreateZipArchive "$publishDir/net462/${projectName}.exe" "$publishDir/${projectName}.exe.zip"