forked from JetBrains/YouTrackSharp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.ps1
49 lines (38 loc) · 2.02 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
[CmdletBinding()]
Param(
[switch]$NoInit,
[Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)]
[string[]]$BuildArguments
)
Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { $host.SetShouldExit(1) }
$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent
###########################################################################
# CONFIGURATION
###########################################################################
$NuGetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$SolutionDirectory = "$PSScriptRoot\..\YouTrackSharp"
$BuildProjectFile = "$PSScriptRoot\.\build\YouTrackSharp.Build.csproj"
$BuildExeFile = "$PSScriptRoot\.\build\bin\debug\YouTrackSharp.Build.exe"
$TempDirectory = "$PSScriptRoot\..\YouTrackSharp\.tmp"
###########################################################################
# PREPARE BUILD
###########################################################################
function ExecSafe([scriptblock] $cmd) {
& $cmd
if ($LastExitCode -ne 0) { throw "The following call failed with exit code $LastExitCode. '$cmd'" }
}
if (!$NoInit) {
md -force $TempDirectory > $null
$NuGetFile = "$TempDirectory\nuget.exe"
$env:NUGET_EXE = $NuGetFile
if (!(Test-Path $NuGetFile)) { (New-Object System.Net.WebClient).DownloadFile($NuGetUrl, $NuGetFile) }
elseif ($NuGetUrl.Contains("latest")) { & $NuGetFile update -Self }
ExecSafe { & $NuGetFile restore $BuildProjectFile -SolutionDirectory $SolutionDirectory }
ExecSafe { & $NuGetFile install Nuke.MSBuildLocator -ExcludeVersion -OutputDirectory $TempDirectory -SolutionDirectory $SolutionDirectory }
}
$MSBuildFile = & "$TempDirectory\Nuke.MSBuildLocator\tools\Nuke.MSBuildLocator.exe"
ExecSafe { & $MSBuildFile $BuildProjectFile }
###########################################################################
# EXECUTE BUILD
###########################################################################
ExecSafe { & $BuildExeFile $BuildArguments }