Reputation: 15091
I have a batch file as follows to clean my UE project.
del *.sln
rmdir /s /q .vs
rmdir /s /q Binaries
rmdir /s /q Intermediate
rmdir /s /q Saved
rmdir /s /q DerivedDataCache
"C:\Program Files (x86)\Epic Games\Launcher\Engine\Binaries\Win64\UnrealVersionSelector.exe" /projectfiles Attaching.uproject
Unfortunately, when I run the batch, I get an error as follows:
I found the last command in the batch by reverse-engineering as shown below:
What is the correct way to generate Visual Studio project files from a batch file?
Upvotes: 3
Views: 8506
Reputation: 1
@echo off
setlocal enabledelayedexpansion
rem Change this to the path to your Unreal Engine's "UnrealVersionSelector.exe"
set "UEVersionSelector=C:\Program Files (x86)\Epic Games\Launcher\Engine\Binaries\Win64\UnrealVersionSelector.exe"
rem Change this to the path to your UnrealBuildTool
set "UnrealBuildTool=C:\Program Files\Epic Games\UE_5.3\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.exe"
rem Get the directory of the batch file
set "BatchFileDir=%~dp0"
rem Find the .uproject file in the batch file directory
for %%i in ("%BatchFileDir%*.uproject") do set "UProjectFile=%%i"
if not defined UProjectFile (
echo .uproject file not found in the batch file directory.
pause
exit /b
)
rem Extract the project name from the .uproject file
for /f "usebackq tokens=2,* delims=:" %%a in ("!UProjectFile!") do (
set "ProjectName=%%~b"
set "ProjectName=!ProjectName:^"=!"
set "ProjectName=!ProjectName: =!"
)
echo Cleaning project files...
rem Remove the Visual Studio solution file if it exists
set "SolutionFile=%BatchFileDir%!ProjectName!.sln"
if exist "!SolutionFile!" (
del "!SolutionFile!"
echo Deleted "!SolutionFile!"
) else (
echo "!SolutionFile!" not found. Skipping deletion.
)
rem Remove Intermediate and Saved folders if they exist without confirmation prompt
rmdir /s /q "!BatchFileDir!Intermediate" 2>nul
rmdir /s /q "!BatchFileDir!Saved" 2>nul
rem Remove the additional files and folders
rmdir /s /q "!BatchFileDir!.vs" 2>nul
del /q "!BatchFileDir!.vsconfig" 2>nul
rmdir /s /q "!BatchFileDir!Binaries" 2>nul
rmdir /s /q "!BatchFileDir!Build" 2>nul
rmdir /s /q "!BatchFileDir!DerivedDataCache" 2>nul
echo Cleaning completed.
echo Generating project files...
rem Generate project files using UnrealVersionSelector
"%UEVersionSelector%" -projectfiles "!UProjectFile!"
echo Generating Visual Studio project files...
rem Generate Visual Studio project files using UnrealBuildTool
"%UnrealBuildTool%" Development Win64 -Project="!UProjectFile!" -TargetType=Editor
echo Generation completed.
rem Pause the script so you can see the output before it closes
pause
Upvotes: 0
Reputation: 15091
After wasting a lot of time, I found the solution. We have to fully qualify the project path.
echo off
del *.sln
rmdir /s /q .vs
rmdir /s /q Binaries
rmdir /s /q Intermediate
rem rmdir /s /q Saved
rmdir /s /q DerivedDataCache
set MyUVS="C:\Program Files (x86)\Epic Games\Launcher\Engine\Binaries\Win64\UnrealVersionSelector.exe"
set MyUBT="f:\Program Files\Epic Games\UE_4.26\Engine\Binaries\DotNET\UnrealBuildTool.exe"
rem change Transformation to your own project name
set MyFullPath="%cd%\Transformation"
%MyUVS% /projectfiles %MyFullPath%.uproject
%MyUBT% Development Win64 -Project=%MyFullPath%.uproject -TargetType=Editor -Progress -NoEngineChanges -NoHotReloadFromIDE
%MyFullPath%.uproject
%MyFullPath%.sln
I hope this answer is also useful for others in the future!
Upvotes: 6