Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2745_EfficientGlobalOptimization/Build.ps1 @ 16667

Last change on this file since 16667 was 16537, checked in by jkarder, 6 years ago

#2745: updated build script

File size: 3.9 KB
Line 
1# find ms build
2$programFilesX86Dir = ($Env:ProgramFiles, ${Env:ProgramFiles(x86)})[[bool]${Env:ProgramFiles(x86)}]
3$locations = @(
4  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Enterprise", "MSBuild", "15.0", "Bin", "amd64")
5  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Enterprise", "MSBuild", "15.0", "Bin")
6  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Community", "MSBuild", "15.0", "Bin", "amd64")
7  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Community", "MSBuild", "15.0", "Bin")
8  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "BuildTools", "MSBuild", "15.0", "Bin", "amd64"),
9  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "BuildTools", "MSBuild", "15.0", "Bin")
10)
11
12$msBuildPath = $undefined
13Foreach ($loc in $locations) {
14  $loc = [System.IO.Path]::Combine($loc, "MSBuild.exe")
15  If ([System.IO.File]::Exists($loc)) {
16    $msBuildPath = $loc
17    Break;
18  }
19}
20
21Try {
22  If ($msBuildPath -eq $undefined) {
23    "Could not locate MSBuild, ABORTING ..."
24    Return
25  }
26
27  $curPath = $MyInvocation.MyCommand.Path
28  $curDir = Split-Path $curPath
29
30  $slnFiles = Get-ChildItem $curDir -Filter *.sln
31
32  If ($slnFiles.Count -le 0) {
33    "No solutions found, ABORTING ..."
34    Return
35  }
36
37  $slnIndices = @()
38
39  If ($slnFiles.Count -eq 1) {
40    "Selecting the only solution found: `"{0}`"" -f $slnFiles[0].Name
41    $slnIndices += 0
42  } Else {
43    "Found the following solutions:"
44
45    ""
46
47    $slnFiles | % { $i = 0 } { ("  {0}. `"{1}`"" -f ($i + 1), $_.Name); $i++ }
48
49    ""
50
51    $success = $false
52
53    # query solution to build
54    $slnIndex = -1
55    Do {
56        $input = Read-Host "Which solution(s) to build? (e.g.: 1 2 3) { 1..$($slnFiles.Count) }"
57        $inputParts = $input -Split " "
58
59        Foreach ($part in $inputParts) {
60          If ($part -eq "") { Continue }
61
62          $success = [int]::TryParse($part, [ref]$slnIndex) -and ($slnIndex -gt 0) -and ($slnIndex -le $slnFiles.Count)
63
64          If ($success) {
65            $slnIndices += $slnIndex - 1
66          } Else {
67            $slnIndices = @()
68            Break
69          }
70        }
71    } While (-Not $success)
72
73    $slnIndices = $slnIndices | Select-Object -Unique
74  }
75
76
77  # query configuration to build
78  $config = "Release"
79  $input = Read-Host "Which configuration to build? [$($config)]"
80  $config = ($config, $input)[[bool]$input]
81
82  # query platform to build
83  $platform = "Any CPU"
84  $input = Read-Host "Which platform to build? [$($platform)]"
85  $platform = ($platform, $input)[[bool]$input]
86
87  # query clean desire
88  $clean = $false
89  Do {
90      $input = Read-Host "Would you like to clean before building? [y/N]"
91      $input = ([string]("n", $input)[[bool]$input]).ToLowerInvariant()
92      $success = $input -eq "n" -or ($clean = $input -eq "y")
93  } While (-Not $success)
94
95  ""
96
97  If ($clean) {
98    Foreach ($slnIndex in $slnIndices) {
99      $solution = $slnFiles[$slnIndex]
100      "Cleaning `"$($solution.Name)`" ..."
101      $args = @(
102        $solution.FullName,
103        "/t:Clean",
104        "/p:Configuration=`"$config`",Platform=`"$platform`"",
105        "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
106      )
107      & $msBuildPath $args
108      "===== CLEAN FINISHED ====="
109    }
110  }
111
112  Foreach ($slnIndex in $slnIndices) {
113    $solution = $slnFiles[$slnIndex]
114    "Building `"$($solution.Name)`" ($config|$platform) ..."
115    $args = @(
116      $solution.FullName,
117      "/t:Build",
118      "/p:Configuration=`"$config`",Platform=`"$platform`"",
119      "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
120    )
121    & $msBuildPath $args
122    "===== BUILD FINISHED ====="
123  }
124} Finally {
125  ""
126
127  Write-Host -NoNewline "Press any key to continue ... "
128
129  [void][System.Console]::ReadKey($true)
130}
Note: See TracBrowser for help on using the repository browser.