/
Build.psm1
81 lines (74 loc) · 2.54 KB
/
Build.psm1
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
Set-StrictMode -Version latest
$ErrorActionPreference = "Stop"
[String]$ScriptDir = Split-Path $script:MyInvocation.MyCommand.Path
Import-Module "$ScriptDir\Helper.psm1"
Import-Module "$ScriptDir\Configuration.psm1"
Import-Module "$ScriptDir\UpdateOutputFileList.psm1"
# -------------------------------------------------------------------------------------------------------------------------------------
function Build
{
Param
(
[Parameter()][string] $SolutionPath = $global:SolutionPath,
[Parameter()][string] $MsbuildVerbosity = 'minimal',
[Parameter()][string[]] $MsbuildConfigurations = $global:BuildConfigurations,
[Parameter()][string[]] $MsbuildPlatforms = $global:BuildPlatforms,
[Parameter()][string] $MsbuildProperties,
[Parameter()][switch] $PauseOnError,
[Parameter()][switch] $SkipConsistencyCheck
)
$SolutionDirectoryPath = Split-Path -Path "$SolutionPath"
$SolutionName = (Get-Item "$SolutionPath").BaseName
Try
{
foreach ($Configuration in $MsbuildConfigurations)
{
foreach ($Platform in $MsbuildPlatforms)
{
# build solution for the selected platform/configuration
Write-Host -ForegroundColor "Green" "Building solution for platform '$Platform' in configuration '$Configuration'..."
$cmd = @($MsbuildPath)
$cmd += "$SolutionPath"
$cmd += "/property:Configuration=$Configuration"
$cmd += "/property:Platform=$Platform"
if ($MsbuildProperties) { $cmd += "/property:$MsbuildProperties" }
$cmd += "/verbosity:$MsbuildVerbosity"
$cmd += "/t:Build"
EnvRunExec $cmd
}
}
# Update output files for given configurations
UpdateOutputFileList `
-SolutionPath "$SolutionPath" `
-PauseOnError:$PauseOnError
# Check consistency of build output
if (!$SkipConsistencyCheck)
{
$OutputFilesListBasePath = "$SolutionDirectoryPath\out-index"
Write-Host -ForegroundColor "Green" "Checking consistency of files in output directories..."
$cmd = @($GitPath)
$cmd += "diff"
$cmd += "--"
$cmd += Resolve-Path -Relative "$OutputFilesListBasePath"
$diff = (EnvRunExec $cmd) | Out-String
if ($diff.Length -ne 0)
{
Write-Host -ForegroundColor "Red" "Encountered a diff for '$OutputFilesListBasePath'. Check build output for new assemblies..."
Write-Host -ForegroundColor "Red" "$diff"
if ($PauseOnError) {
Read-Host "Press ANY key..."
}
exit(-1)
}
}
}
Catch [Exception]
{
# tell the caller it has all gone wrong
echo $_.Exception|format-list -force
if ($PauseOnError) {
Read-Host "Press ANY key..."
}
exit(-1)
}
}