Skip to content

Commit 423f453

Browse files
committed
Improve release build batch script.
1 parent d4129d1 commit 423f453

2 files changed

Lines changed: 143 additions & 41 deletions

File tree

build.bat

Lines changed: 138 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,150 @@
1-
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2-
:: Install CoreKeepersWorkshop Via MSBuild ::
3-
:: Gihub https://github.com/RussDev7/CoreKeepersWorkshop ::
4-
:: Developed and maintained by RussDev7 / Discord: dannyruss ::
5-
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1+
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2+
:: Build The CoreKeepersWorkshop Project Via Batch ::
3+
:: GitHub: https://github.com/RussDev7/CoreKeepersWorkshop ::
4+
:: Developed and maintained by RussDev7 / Discord: dannyruss ::
5+
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
66
@ECHO OFF
7+
SETLOCAL ENABLEDELAYEDEXPANSION
78

8-
Rem | Set Params
9-
Set "VersionPrefix=1.3.6.73"
10-
Set "filename=CoreKeeperInventoryEditor-%VersionPrefix%"
9+
REM ============================================================
10+
REM Paths
11+
REM ============================================================
12+
SET "RootDir=%~dp0"
13+
SET "SolutionPath=%RootDir%src\CoreKeeperInventoryEditor.sln"
14+
SET "ProjectOutput=%RootDir%src\CoreKeeperInventoryEditor\bin\x64\Release"
15+
SET "ReleaseDir=%RootDir%release"
16+
SET "ExeName=CoreKeepersWorkshop.exe"
1117

12-
Rem | Put the expected location of vswhere into a variable.
13-
set "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
18+
REM ============================================================
19+
REM Find Visual Studio / Build Tools MSBuild
20+
REM ============================================================
21+
SET "VSWHERE=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe"
1422

15-
Rem | Ask for the newest VS install that includes Microsoft.Component.MSBuild
16-
Rem | and let vswhere do the glob‑expansion that finds MSBuild.exe.
17-
for /f "usebackq tokens=*" %%I in (`
18-
"%VSWHERE%" -latest ^
19-
-products * ^
20-
-requires Microsoft.Component.MSBuild ^
21-
-find MSBuild\**\Bin\MSBuild.exe
22-
`) do (
23-
set "MSBUILD=%%I"
23+
IF NOT EXIST "%VSWHERE%" (
24+
ECHO ERROR: vswhere.exe was not found.
25+
ECHO Install Visual Studio or Visual Studio Build Tools with .NET desktop build tools.
26+
PAUSE
27+
EXIT /B 1
2428
)
2529

26-
Rem | Install SLN under x64 profile.
27-
"%MSBUILD%" ".\src\CoreKeeperInventoryEditor.sln" /p:Configuration=Release /p:Platform=x64
30+
FOR /F "usebackq tokens=*" %%I IN (`"%VSWHERE%" -latest -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe`) DO (
31+
SET "MSBUILD=%%I"
32+
)
33+
34+
IF NOT DEFINED MSBUILD (
35+
ECHO ERROR: Could not find Visual Studio MSBuild.
36+
ECHO Install Visual Studio Build Tools and include MSBuild / .NET desktop workload.
37+
PAUSE
38+
EXIT /B 1
39+
)
2840

29-
Rem | Delete Paths & Create Paths
30-
if exist ".\release\" rmdir /s /q ".\release"
31-
mkdir ".\release"
41+
ECHO Using MSBuild:
42+
ECHO "%MSBUILD%"
43+
ECHO(
3244

33-
Rem | Copy Over Items
34-
xcopy /E /Y ".\src\CoreKeeperInventoryEditor\bin\x64\Release" ".\release\%filename%\"
45+
REM ============================================================
46+
REM Build Solution
47+
REM ============================================================
48+
ECHO Building CoreKeeperInventoryEditor.sln...
3549

36-
Rem | Clean Up Files
37-
if exist ".\release\*.xml" del /f /q /s ".\release\*.xml"
38-
if exist ".\release\*.pdb" del /f /q /s ".\release\*.pdb"
39-
if exist ".\release\*.config" del /f /q /s ".\release\*.config"
50+
"%MSBUILD%" "%SolutionPath%" ^
51+
/m ^
52+
/restore ^
53+
/p:Configuration=Release ^
54+
/p:Platform=x64
4055

41-
Rem | Delete & Create ZIP Release
42-
if exist ".\%filename%.zip" (del /f ".\%filename%.zip")
43-
powershell.exe -nologo -noprofile -command "Compress-Archive -Path ".\release\*" -DestinationPath ".\%filename%.zip""
56+
IF ERRORLEVEL 1 (
57+
ECHO(
58+
ECHO Build failed.
59+
PAUSE
60+
EXIT /B 1
61+
)
4462

45-
Rem | Operation Complete
46-
echo(
47-
pause
63+
REM ============================================================
64+
REM Read File Version From Built EXE
65+
REM ============================================================
66+
IF NOT EXIST "%ProjectOutput%\%ExeName%" (
67+
ECHO ERROR: Built EXE was not found:
68+
ECHO "%ProjectOutput%\%ExeName%"
69+
PAUSE
70+
EXIT /B 1
71+
)
72+
73+
FOR /F "usebackq tokens=*" %%V IN (`powershell.exe -NoLogo -NoProfile -Command "(Get-Item '%ProjectOutput%\%ExeName%').VersionInfo.FileVersion"`) DO (
74+
SET "VersionPrefix=%%V"
75+
)
76+
77+
IF NOT DEFINED VersionPrefix (
78+
ECHO ERROR: Could not read file version from EXE.
79+
PAUSE
80+
EXIT /B 1
81+
)
82+
83+
SET "FileName=CoreKeeperInventoryEditor-%VersionPrefix%"
84+
85+
ECHO(
86+
ECHO Detected File Version: %VersionPrefix%
87+
ECHO Release Name: %FileName%
88+
ECHO(
89+
90+
REM ============================================================
91+
REM Recreate Release Folder
92+
REM ============================================================
93+
IF EXIST "%ReleaseDir%" (
94+
RMDIR /S /Q "%ReleaseDir%"
95+
)
96+
97+
MKDIR "%ReleaseDir%\%FileName%"
98+
99+
IF ERRORLEVEL 1 (
100+
ECHO(
101+
ECHO Failed to create release folder.
102+
PAUSE
103+
EXIT /B 1
104+
)
105+
106+
REM ============================================================
107+
REM Copy Build Output
108+
REM ============================================================
109+
XCOPY /E /Y /I "%ProjectOutput%\*" "%ReleaseDir%\%FileName%\"
110+
111+
IF ERRORLEVEL 1 (
112+
ECHO(
113+
ECHO Copy failed.
114+
PAUSE
115+
EXIT /B 1
116+
)
117+
118+
REM ============================================================
119+
REM Clean Release Files
120+
REM ============================================================
121+
DEL /F /Q /S "%ReleaseDir%\*.xml" >NUL 2>&1
122+
DEL /F /Q /S "%ReleaseDir%\*.pdb" >NUL 2>&1
123+
DEL /F /Q /S "%ReleaseDir%\*.config" >NUL 2>&1
124+
125+
REM ============================================================
126+
REM Create ZIP Release
127+
REM ============================================================
128+
IF EXIST "%RootDir%%FileName%.zip" (
129+
DEL /F /Q "%RootDir%%FileName%.zip"
130+
)
131+
132+
powershell.exe -NoLogo -NoProfile -Command ^
133+
"Compress-Archive -Path '%ReleaseDir%\%FileName%' -DestinationPath '%RootDir%%FileName%.zip' -Force"
134+
135+
IF ERRORLEVEL 1 (
136+
ECHO(
137+
ECHO ZIP creation failed.
138+
PAUSE
139+
EXIT /B 1
140+
)
48141

142+
REM ============================================================
143+
REM Operation Complete
144+
REM ============================================================
145+
ECHO(
146+
ECHO Build complete.
147+
ECHO Created: "%RootDir%%FileName%.zip"
148+
ECHO(
149+
PAUSE
150+
ENDLOCAL

clean.bat

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2-
:: Clean The CoreKeepersWorkshop Project Via Batch ::
3-
:: Gihub https://github.com/RussDev7/CoreKeepersWorkshop ::
4-
:: Developed and maintained by RussDev7 / Discord: dannyruss ::
5-
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
1+
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
2+
:: Clean The CoreKeepersWorkshop Project Via Batch ::
3+
:: GitHub: https://github.com/RussDev7/CoreKeepersWorkshop ::
4+
:: Developed and maintained by RussDev7 / Discord: dannyruss ::
5+
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
66
@ECHO OFF
77

88
Rem | Check If Clean Is Necessary

0 commit comments

Comments
 (0)