Skip to content

Commit

Permalink
Adds auto detection for visual studio 2019 and 2022.
Browse files Browse the repository at this point in the history
  • Loading branch information
geo-at-github committed Apr 3, 2024
1 parent 7f0cad5 commit 417e98a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
55 changes: 48 additions & 7 deletions Build.cmd
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
@echo off

REM Default VS paths to check if no Paths.cmd file exists
set VISUAL_STUDIO_PATH_0="%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe"
set VISUAL_STUDIO_PATH_1="%programfiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe"
set VISUAL_STUDIO_PATH_2="%programfiles(x86)%\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild.exe"
set VISUAL_STUDIO_PATH_3="%programfiles(x86)%\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild.exe"

pushd "%~dp0"
if exist Debug rd /s /q Debug
if exist Release rd /s /q Release
if exist x64 rd /s /q x64

IF NOT EXIST "Paths.cmd" (
ECHO Please copy "Paths.cmd.template", enter your Visual Studio path and rename it to "Paths.cmd".
PAUSE
GOTO exit
if exist "Paths.cmd" (
REM Prefer Paths.cmd as Visual Studio path source if it exists.
call Paths.cmd
goto build
) else (
REM Otherwise try to auto-detect the Visual Studio path.
if exist %VISUAL_STUDIO_PATH_0% (
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_0%
goto build
)

call Paths.cmd
"%VISUAL_STUDIO_PATH%" /p:Configuration=Release
if exist %VISUAL_STUDIO_PATH_1% (
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_1%
goto build
)

if exist %VISUAL_STUDIO_PATH_2% (
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_2%
goto build
)

if exist %VISUAL_STUDIO_PATH_3% (
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_3%
goto build
)

REM No default path found. Let the user know what to do.
echo No Visual Studio installation found. Please configure it manually.
echo 1. Copy 'Paths.cmd.template'.
echo 2. Rename it to 'Paths.cmd'.
echo 3. Enter your Visual Studio path in there.
echo 4. Restart the build.
REM Allow disabling pause to support non-interacting build chains.
if NOT "%~1"=="-no-pause" pause
goto end
)

:build
REM Log the used Vistual Studio version.
@echo on
%VISUAL_STUDIO_PATH% /p:Configuration=Release
@echo off

:exit
:end
popd
@echo on
12 changes: 2 additions & 10 deletions Paths.cmd.template
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
@echo off
:: Set your Visual Studio path here.
:: TODO: Make visual studio path auto detection.

:: Enterprise path
SET VISUAL_STUDIO_PATH=%programfiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe

:: Community path
::SET VISUAL_STUDIO_PATH=%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe

echo Using Visual Studio path:%VISUAL_STUDIO_PATH%
REM Set your Visual Studio path here.
SET VISUAL_STUDIO_PATH="%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe"
@echo on

0 comments on commit 417e98a

Please sign in to comment.