Free cookie consent management tool by TermsFeed Policy Generator

source: stable/Build.ps1 @ 17173

Last change on this file since 17173 was 16754, checked in by jkarder, 6 years ago

#2951: merged r16221, r16223:16224 r16381 and r16624 into stable

File size: 3.9 KB
RevLine 
[16221]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
[16754]21Try {
22  If ($msBuildPath -eq $undefined) {
23    "Could not locate MSBuild, ABORTING ..."
24    Return
25  }
26
[16221]27  $curPath = $MyInvocation.MyCommand.Path
28  $curDir = Split-Path $curPath
29
30  $slnFiles = Get-ChildItem $curDir -Filter *.sln
31
[16754]32  If ($slnFiles.Count -le 0) {
33    "No solutions found, ABORTING ..."
34    Return
35  }
[16221]36
[16754]37  $slnIndices = @()
[16221]38
[16754]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:"
[16221]44
[16754]45    ""
[16221]46
[16754]47    $slnFiles | % { $i = 0 } { ("  {0}. `"{1}`"" -f ($i + 1), $_.Name); $i++ }
[16221]48
[16754]49    ""
[16221]50
[16754]51    $success = $false
[16221]52
[16754]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 " "
[16221]58
[16754]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          }
[16221]70        }
[16754]71    } While (-Not $success)
[16221]72
[16754]73    $slnIndices = $slnIndices | Select-Object -Unique
74  }
[16221]75
[16754]76
[16221]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
[16754]97  If ($clean) {
[16221]98    Foreach ($slnIndex in $slnIndices) {
99      $solution = $slnFiles[$slnIndex]
100      "Cleaning `"$($solution.Name)`" ..."
101      $args = @(
102        $solution.FullName,
103        "/t:Clean",
[16754]104        "/p:Configuration=`"$config`",Platform=`"$platform`"",
[16221]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]
[16754]114    "Building `"$($solution.Name)`" ($config|$platform) ..."
[16221]115    $args = @(
116      $solution.FullName,
[16754]117      "/t:Restore,Build",
118      "/p:Configuration=`"$config`",Platform=`"$platform`"",
[16221]119      "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
120    )
121    & $msBuildPath $args
122    "===== BUILD FINISHED ====="
123  }
[16754]124} Finally {
125  ""
[16221]126
[16754]127  Write-Host -NoNewline "Press any key to continue ... "
[16221]128
[16754]129  [void][System.Console]::ReadKey($true)
130}
Note: See TracBrowser for help on using the repository browser.