@echo off
type build.logo
echo finding Visual Studio...
rem VS2017U2 contains vswhere.exe
if "%VSWHERE%"=="" set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"

for /f "usebackq tokens=*" %%i in (`"%VSWHERE%" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
  set InstallDir=%%i
)

set MSBuildExe=MSBuild\Current\Bin\MSBuild.exe

if exist "%InstallDir%\%MSBuildExe%" (
  echo ...
) else (
  set MSBuildExe=MSBuild\15.0\Bin\MSBuild.exe
)
  
if exist "%InstallDir%\%MSBuildExe%" (
  echo Studio found at "%InstallDir%"
  echo MSBuild found at "%InstallDir%\%MSBuildExe%"
) else (
  echo Error: No Visual Studio or MSBuild found.
)