Skip to content

Commit 417e98a

Browse files
committed
Adds auto detection for visual studio 2019 and 2022.
1 parent 7f0cad5 commit 417e98a

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

Diff for: Build.cmd

+48-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,59 @@
11
@echo off
2+
3+
REM Default VS paths to check if no Paths.cmd file exists
4+
set VISUAL_STUDIO_PATH_0="%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe"
5+
set VISUAL_STUDIO_PATH_1="%programfiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe"
6+
set VISUAL_STUDIO_PATH_2="%programfiles(x86)%\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild.exe"
7+
set VISUAL_STUDIO_PATH_3="%programfiles(x86)%\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\msbuild.exe"
8+
29
pushd "%~dp0"
310
if exist Debug rd /s /q Debug
411
if exist Release rd /s /q Release
512
if exist x64 rd /s /q x64
613

7-
IF NOT EXIST "Paths.cmd" (
8-
ECHO Please copy "Paths.cmd.template", enter your Visual Studio path and rename it to "Paths.cmd".
9-
PAUSE
10-
GOTO exit
14+
if exist "Paths.cmd" (
15+
REM Prefer Paths.cmd as Visual Studio path source if it exists.
16+
call Paths.cmd
17+
goto build
18+
) else (
19+
REM Otherwise try to auto-detect the Visual Studio path.
20+
if exist %VISUAL_STUDIO_PATH_0% (
21+
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_0%
22+
goto build
1123
)
1224

13-
call Paths.cmd
14-
"%VISUAL_STUDIO_PATH%" /p:Configuration=Release
25+
if exist %VISUAL_STUDIO_PATH_1% (
26+
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_1%
27+
goto build
28+
)
29+
30+
if exist %VISUAL_STUDIO_PATH_2% (
31+
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_2%
32+
goto build
33+
)
34+
35+
if exist %VISUAL_STUDIO_PATH_3% (
36+
set VISUAL_STUDIO_PATH=%VISUAL_STUDIO_PATH_3%
37+
goto build
38+
)
39+
40+
REM No default path found. Let the user know what to do.
41+
echo No Visual Studio installation found. Please configure it manually.
42+
echo 1. Copy 'Paths.cmd.template'.
43+
echo 2. Rename it to 'Paths.cmd'.
44+
echo 3. Enter your Visual Studio path in there.
45+
echo 4. Restart the build.
46+
REM Allow disabling pause to support non-interacting build chains.
47+
if NOT "%~1"=="-no-pause" pause
48+
goto end
49+
)
50+
51+
:build
52+
REM Log the used Vistual Studio version.
53+
@echo on
54+
%VISUAL_STUDIO_PATH% /p:Configuration=Release
55+
@echo off
1556

16-
:exit
57+
:end
1758
popd
1859
@echo on

Diff for: Paths.cmd.template

+2-10
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11
@echo off
2-
:: Set your Visual Studio path here.
3-
:: TODO: Make visual studio path auto detection.
4-
5-
:: Enterprise path
6-
SET VISUAL_STUDIO_PATH=%programfiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe
7-
8-
:: Community path
9-
::SET VISUAL_STUDIO_PATH=%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe
10-
11-
echo Using Visual Studio path:%VISUAL_STUDIO_PATH%
2+
REM Set your Visual Studio path here.
3+
SET VISUAL_STUDIO_PATH="%programfiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\msbuild.exe"
124
@echo on

0 commit comments

Comments
 (0)