Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/Build.ps1 @ 17114

Last change on this file since 17114 was 17052, checked in by jkarder, 5 years ago

#2875: Updated search for MSBuild location in build script

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