forked from yarseyah/sentinel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Make-Installer.ps1
120 lines (99 loc) · 3.66 KB
/
Make-Installer.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
function Get-MsBuildCommand() {
$findCommand = Get-Command msbuild -ErrorAction SilentlyContinue
if ( $findCommand -ne $null ) {
return "msbuild"
}
# Since VS2017, there is a bundled command called vswhere
# - vswhere is included with the installer as of Visual Studio 2017 version 15.2 and later,
# and can be found at the following location:
# %ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
if ( (Get-Command $vsWhere -ErrorAction SilentlyContinue) -eq $null) {
Write-Error "Unable to find 'vswhere'"
}
else {
$vspath = & $vsWhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath
if ($vspath) {
$msbuild = join-path $vspath 'MSBuild\15.0\Bin\MSBuild.exe'
if ( Test-Path $msbuild ) {
return $msbuild
} else {
Write-Error "Should be located at $msbuild but Test-Path failed"
}
}
}
return $null;
}
function Get-NugetCommand() {
$findCommand = Get-Command nuget -ErrorAction SilentlyContinue
if ( $findCommand -ne $null ) {
return "nuget"
}
# $installedNuget = ".\packages\NuGet.CommandLine.4.6.2\tools\NuGet.exe"
$installedNuget = (Get-ChildItem -Path .\packages\ -Recurse -Include NuGet.exe | Select-Object -First 1)
if ( Test-Path $installedNuget ) {
return $installedNuget
} else {
return $null;
}
}
function Get-SquirrelCommand() {
$findCommand = Get-Command squirrel.exe -ErrorAction SilentlyContinue
if ( $findCommand -ne $null ) {
return "squirrel.exe"
}
$squirrel = (Get-ChildItem -Path .\packages\ -Recurse -Include squirrel.exe | Select-Object -First 1)
if ( Test-Path $squirrel ) {
return $squirrel
} else {
return $null;
}
}
$msbuild = Get-MsBuildCommand
if ( $msbuild -eq $null ) {
Write-Error "Unable to locate MSBuild"
Exit
}
$nuget = Get-NugetCommand
if ( $nuget -eq $null ) {
Write-Error "Unable to locate Nuget"
Exit
}
$squirrel = Get-SquirrelCommand
if ( $squirrel -eq $null ) {
Write-Error "Unable to locate Squirrel"
Exit
}
Write-Output "MSBuild = $msbuild"
Write-Output "Nuget = $nuget"
Write-Output "Squirrel = $squirrel"
$solutionFile = "Sentinel.sln"
$nuspecFile = "Sentinel.nuspec"
$buildConfiguration = "Release"
& $msbuild /t:Clean /p:Configuration=$buildConfiguration $solutionFile
& $msbuild /t:Build /p:Configuration=$buildConfiguration $solutionFile
if ($LASTEXITCODE -eq 0) {
$basePath = "Sentinel\Bin\$buildConfiguration"
$application = "$basePath\Sentinel.exe"
$version = (get-item $application).VersionInfo.ProductVersion
Write-Output "Packaging up $application [$version]"
& $nuget pack $nuspecFile -Version $version -BasePath $basePath
$package = "Sentinel.$version.nupkg"
if ( Test-Path $package ) {
Write-Output "Packed into $package"
$releasesLocation = "Releases"
# Squirrel doesn't wait, so cheat by pipelining it with | Write-Output
# See https://github.com/Squirrel/Squirrel.Windows/issues/489
& $squirrel --releasify $package --no-msi --releaseDir=$releasesLocation | Write-Output
if ( $LASTEXITCODE -eq 0) {
# Give the installer a sensible name
Move-Item (Join-Path $releasesLocation "setup.exe") `
(Join-Path $releasesLocation "Sentinel-Setup-$version.exe") `
-Force
}
} else {
Write-Error "Problem creating package"
}
} else {
Write-Error "Failed to build!"
}