[16221] | 1 | # find ms build
|
---|
| 2 | $programFilesX86Dir = ($Env:ProgramFiles, ${Env:ProgramFiles(x86)})[[bool]${Env:ProgramFiles(x86)}]
|
---|
[17052] | 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")
|
---|
[16221] | 7 |
|
---|
| 8 | $msBuildPath = $undefined
|
---|
[17052] | 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 | }
|
---|
[16221] | 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
[16381] | 30 | Try {
|
---|
| 31 | If ($msBuildPath -eq $undefined) {
|
---|
| 32 | "Could not locate MSBuild, ABORTING ..."
|
---|
| 33 | Return
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[17052] | 36 | "MSBuild located at `"{0}`"." -f $msBuildPath
|
---|
| 37 |
|
---|
[16221] | 38 | $curPath = $MyInvocation.MyCommand.Path
|
---|
| 39 | $curDir = Split-Path $curPath
|
---|
| 40 |
|
---|
| 41 | $slnFiles = Get-ChildItem $curDir -Filter *.sln
|
---|
| 42 |
|
---|
[16381] | 43 | If ($slnFiles.Count -le 0) {
|
---|
| 44 | "No solutions found, ABORTING ..."
|
---|
| 45 | Return
|
---|
| 46 | }
|
---|
[16221] | 47 |
|
---|
[16381] | 48 | $slnIndices = @()
|
---|
[16221] | 49 |
|
---|
[16381] | 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:"
|
---|
[16221] | 55 |
|
---|
[16381] | 56 | ""
|
---|
[16221] | 57 |
|
---|
[16381] | 58 | $slnFiles | % { $i = 0 } { (" {0}. `"{1}`"" -f ($i + 1), $_.Name); $i++ }
|
---|
[16221] | 59 |
|
---|
[16381] | 60 | ""
|
---|
[16221] | 61 |
|
---|
[16381] | 62 | $success = $false
|
---|
[16221] | 63 |
|
---|
[16381] | 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 " "
|
---|
[16221] | 69 |
|
---|
[16381] | 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 | }
|
---|
[16221] | 81 | }
|
---|
[16381] | 82 | } While (-Not $success)
|
---|
[16221] | 83 |
|
---|
[16381] | 84 | $slnIndices = $slnIndices | Select-Object -Unique
|
---|
| 85 | }
|
---|
[16221] | 86 |
|
---|
[16381] | 87 |
|
---|
[16221] | 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 |
|
---|
[16381] | 108 | If ($clean) {
|
---|
[16221] | 109 | Foreach ($slnIndex in $slnIndices) {
|
---|
| 110 | $solution = $slnFiles[$slnIndex]
|
---|
| 111 | "Cleaning `"$($solution.Name)`" ..."
|
---|
| 112 | $args = @(
|
---|
| 113 | $solution.FullName,
|
---|
| 114 | "/t:Clean",
|
---|
[16223] | 115 | "/p:Configuration=`"$config`",Platform=`"$platform`"",
|
---|
[16221] | 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]
|
---|
[16223] | 125 | "Building `"$($solution.Name)`" ($config|$platform) ..."
|
---|
[16221] | 126 | $args = @(
|
---|
| 127 | $solution.FullName,
|
---|
[16624] | 128 | "/t:Restore,Build",
|
---|
[16223] | 129 | "/p:Configuration=`"$config`",Platform=`"$platform`"",
|
---|
[16221] | 130 | "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
|
---|
| 131 | )
|
---|
| 132 | & $msBuildPath $args
|
---|
| 133 | "===== BUILD FINISHED ====="
|
---|
| 134 | }
|
---|
[16381] | 135 | } Finally {
|
---|
| 136 | ""
|
---|
[16221] | 137 |
|
---|
[16381] | 138 | Write-Host -NoNewline "Press any key to continue ... "
|
---|
[16221] | 139 |
|
---|
[16381] | 140 | [void][System.Console]::ReadKey($true)
|
---|
| 141 | }
|
---|