如何使用批处理文件从虚幻引擎 .uproject 文件生成 Visual Studio 项目文件?

问题描述 投票:0回答:2

我有一个如下的批处理文件来清理我的 UE 项目。

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

不幸的是,当我运行批处理时,出现如下错误:

我通过逆向工程找到了该批处理中的最后一个命令,如下所示:

问题

从批处理文件生成 Visual Studio 项目文件的正确方法是什么?

batch-file unreal-engine4 unreal-development-kit
2个回答
3
投票

浪费了很多时间后,我找到了解决方案。我们必须完全限定项目路径。

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

我希望这个答案对未来的其他人也有用!


0
投票

谢谢兄弟,我用 ChatGPT 稍微改进了它,它找到了项目

@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
© www.soinside.com 2019 - 2024. All rights reserved.