Index: /branches/2745_EfficientGlobalOptimization/Build.cmd
===================================================================
--- /branches/2745_EfficientGlobalOptimization/Build.cmd	(revision 16536)
+++ /branches/2745_EfficientGlobalOptimization/Build.cmd	(revision 16537)
@@ -1,104 +1,2 @@
 @ECHO OFF
-
-SET CLEANBEFOREBUILD=
-
-SET SELECTED=
-SET CONFIGURATION=
-SET PLATFORM=
-
-IF "%~1"=="" GOTO :prompt_solution
-
-SET SELECTED=%1
-IF NOT EXIST %SELECTED% (
-  ECHO Solution file %SELECTED% could not be found.
-  GOTO :end
-)
-ECHO Building solution %SELECTED% ...
-GOTO :config_selection
-
-:prompt_solution
-SET /A COUNT=0
-FOR /F "tokens=*" %%A IN ('dir /B *.sln') DO (
-  CALL :forloopbody "%%A"
-)
-
-IF "%COUNT%"=="1" (
-  SET SELECTED=%SOLUTIONS.1%
-  ECHO Building %SOLUTIONS.1% as it is the only solution that was found ...
-  GOTO :config_selection
-)
-
-ECHO Found the following solutions:
-FOR /F "tokens=2* delims=.=" %%A IN ('SET SOLUTIONS.') DO ECHO %%A = %%B
-ECHO.
-SET /P SOLUTIONINDEX=Which solution to build? Type the number: 
-
-SET SELECTED=""
-FOR /F "tokens=2* delims=.=" %%A IN ('SET SOLUTIONS.') DO (
-  IF "%%A"=="%SOLUTIONINDEX%" SET SELECTED=%%B
-)
-
-IF %SELECTED%=="" GOTO :eof
-
-:config_selection
-IF "%~2"==""  GOTO :prompt_config
-
-SET CONFIGURATION=%~2
-ECHO Building configuration %CONFIGURATION% ...
-GOTO :platform_selection
-
-:prompt_config
-SET /P CONFIGURATION=Which configuration to build [Release]: 
-IF "%CONFIGURATION%"=="" SET CONFIGURATION=Release
-
-:platform_selection
-IF "%~3"=="" GOTO :prompt_platform
-  
-SET PLATFORM=%~3
-ECHO Building platform %PLATFORM% ...
-GOTO :clean
-
-:prompt_platform
-SET /P PLATFORM=Which platform to build [Any CPU]: 
-IF "%PLATFORM%"=="" SET PLATFORM=Any CPU
-
-:clean
-IF "%~4"=="" GOTO :prompt_clean
-
-SET CLEANBEFOREBUILD=%~4
-GOTO :main
-
-:prompt_clean
-SET /P CLEANBEFOREBUILD=Would you like to clean before building [n]: 
-IF "%CLEANBEFOREBUILD%"=="" SET CLEANBEFOREBUILD=n
-
-:main
-REM First find the path to the msbuild.exe by performing a registry query
-FOR /F "tokens=1,3 delims=	 " %%A IN ('REG QUERY "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0"') DO (
-  IF "%%A"=="MSBuildToolsPath" SET MSBUILDPATH=%%B)
-
-REM Then execute msbuild to clean and build the solution
-REM Disable that msbuild creates a cache file of the solution
-SET MSBuildUseNoSolutionCache=1
-REM Run msbuild to clean and then build
-IF "%CLEANBEFOREBUILD%" NEQ "n" (
-  ECHO Cleaning ...
-  %MSBUILDPATH%msbuild.exe %SELECTED% /target:Clean /p:Configuration="%CONFIGURATION%",Platform="%PLATFORM%" /m:2 /nologo /verbosity:q /clp:ErrorsOnly
-)
-ECHO Building ...
-%MSBUILDPATH%msbuild.exe %SELECTED% /target:Build /p:Configuration="%CONFIGURATION%",Platform="%PLATFORM%" /m:2 /nologo /verbosity:q /clp:ErrorsOnly
-
-ECHO.
-ECHO DONE.
-
-:end
-
-PAUSE
-
-GOTO :eof
-
-REM This workaround is necessary so that COUNT gets reevaluated
-:forloopbody
-SET /A COUNT+=1
-SET SOLUTIONS.%COUNT%=%1
-GOTO :eof
+powershell.exe .\Build.ps1
Index: /branches/2745_EfficientGlobalOptimization/Build.ps1
===================================================================
--- /branches/2745_EfficientGlobalOptimization/Build.ps1	(revision 16537)
+++ /branches/2745_EfficientGlobalOptimization/Build.ps1	(revision 16537)
@@ -0,0 +1,130 @@
+﻿# find ms build
+$programFilesX86Dir = ($Env:ProgramFiles, ${Env:ProgramFiles(x86)})[[bool]${Env:ProgramFiles(x86)}]
+$locations = @(
+  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Enterprise", "MSBuild", "15.0", "Bin", "amd64")
+  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Enterprise", "MSBuild", "15.0", "Bin")
+  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Community", "MSBuild", "15.0", "Bin", "amd64")
+  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "Community", "MSBuild", "15.0", "Bin")
+  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "BuildTools", "MSBuild", "15.0", "Bin", "amd64"),
+  [System.IO.Path]::Combine($programFilesX86Dir, "Microsoft Visual Studio", "2017", "BuildTools", "MSBuild", "15.0", "Bin")
+)
+
+$msBuildPath = $undefined
+Foreach ($loc in $locations) {
+  $loc = [System.IO.Path]::Combine($loc, "MSBuild.exe")
+  If ([System.IO.File]::Exists($loc)) {
+    $msBuildPath = $loc
+    Break;
+  }
+}
+
+Try {
+  If ($msBuildPath -eq $undefined) {
+    "Could not locate MSBuild, ABORTING ..."
+    Return
+  }
+
+  $curPath = $MyInvocation.MyCommand.Path
+  $curDir = Split-Path $curPath
+
+  $slnFiles = Get-ChildItem $curDir -Filter *.sln
+
+  If ($slnFiles.Count -le 0) {
+    "No solutions found, ABORTING ..."
+    Return
+  }
+
+  $slnIndices = @()
+
+  If ($slnFiles.Count -eq 1) {
+    "Selecting the only solution found: `"{0}`"" -f $slnFiles[0].Name
+    $slnIndices += 0
+  } Else {
+    "Found the following solutions:"
+
+    ""
+
+    $slnFiles | % { $i = 0 } { ("  {0}. `"{1}`"" -f ($i + 1), $_.Name); $i++ }
+
+    ""
+
+    $success = $false
+
+    # query solution to build
+    $slnIndex = -1
+    Do {
+        $input = Read-Host "Which solution(s) to build? (e.g.: 1 2 3) { 1..$($slnFiles.Count) }"
+        $inputParts = $input -Split " "
+
+        Foreach ($part in $inputParts) {
+          If ($part -eq "") { Continue }
+
+          $success = [int]::TryParse($part, [ref]$slnIndex) -and ($slnIndex -gt 0) -and ($slnIndex -le $slnFiles.Count)
+
+          If ($success) {
+            $slnIndices += $slnIndex - 1
+          } Else {
+            $slnIndices = @()
+            Break
+          }
+        }
+    } While (-Not $success)
+
+    $slnIndices = $slnIndices | Select-Object -Unique
+  }
+
+
+  # query configuration to build
+  $config = "Release"
+  $input = Read-Host "Which configuration to build? [$($config)]"
+  $config = ($config, $input)[[bool]$input]
+
+  # query platform to build
+  $platform = "Any CPU"
+  $input = Read-Host "Which platform to build? [$($platform)]"
+  $platform = ($platform, $input)[[bool]$input]
+
+  # query clean desire
+  $clean = $false
+  Do {
+      $input = Read-Host "Would you like to clean before building? [y/N]"
+      $input = ([string]("n", $input)[[bool]$input]).ToLowerInvariant()
+      $success = $input -eq "n" -or ($clean = $input -eq "y")
+  } While (-Not $success)
+
+  ""
+
+  If ($clean) {
+    Foreach ($slnIndex in $slnIndices) {
+      $solution = $slnFiles[$slnIndex]
+      "Cleaning `"$($solution.Name)`" ..."
+      $args = @(
+        $solution.FullName,
+        "/t:Clean",
+        "/p:Configuration=`"$config`",Platform=`"$platform`"",
+        "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
+      )
+      & $msBuildPath $args
+      "===== CLEAN FINISHED ====="
+    }
+  }
+
+  Foreach ($slnIndex in $slnIndices) {
+    $solution = $slnFiles[$slnIndex]
+    "Building `"$($solution.Name)`" ($config|$platform) ..."
+    $args = @(
+      $solution.FullName,
+      "/t:Build",
+      "/p:Configuration=`"$config`",Platform=`"$platform`"",
+      "/m", "/nologo", "/verbosity:q", "/clp:ErrorsOnly"
+    )
+    & $msBuildPath $args
+    "===== BUILD FINISHED ====="
+  }
+} Finally {
+  ""
+
+  Write-Host -NoNewline "Press any key to continue ... "
+
+  [void][System.Console]::ReadKey($true)
+}
