Files
UnrealEngineUWP/Engine/Build/BatchFiles/GenerateProjectFiles.bat
Joakim Lindqvist 4aa09904f2 UnrealBuildTool now supports running as a net core project.
Added a set of netcore csprojs to BuildUtilities and DotnetUtilities that build to a seperate output folder. This allows other tools to still target .net framework (like UAT for instance).
UBT is still by default targeted as .net framework.

Note that UBT built for net core has a different output directory Engine/Binaries/DotNet/UnrealBuildTool/UnrealBuildTool.exe - this is due to how a netcore project output looks with signficantly more files that are related to that application (that would be overwritten if using a shared directory).

To opt in to this set UE_USE_DOTNET=1 environment variable.
Please note that due to the changed output directory a lot of tooling will likely break at this point.

#rb ben.marsh

[CL 14419918 by Joakim Lindqvist in ue5-main branch]
2020-10-05 08:13:04 -04:00

169 lines
6.6 KiB
Batchfile
Executable File

@echo off
rem ## Unreal Engine 5 Visual Studio project setup script
rem ## Copyright Epic Games, Inc. All Rights Reserved.
rem ##
rem ## This script is expecting to exist in the UE5 root directory. It will not work correctly
rem ## if you copy it to a different location and run it.
setlocal
echo Setting up Unreal Engine 5 project files...
rem ## First, make sure the batch file exists in the folder we expect it to. This is necessary in order to
rem ## verify that our relative path to the /Engine/Source directory is correct
if not exist "%~dp0..\..\Source" goto Error_BatchFileInWrongLocation
rem ## Change the CWD to /Engine/Source. We always need to run UnrealBuildTool from /Engine/Source!
pushd "%~dp0..\..\Source"
if not exist ..\Build\BatchFiles\GenerateProjectFiles.bat goto Error_BatchFileInWrongLocation
rem ## Check to make sure that we have a Binaries directory with at least one dependency that we know that UnrealBuildTool will need
rem ## in order to run. It's possible the user acquired source but did not download and unpack the other prerequiste binaries.
if not exist ..\Build\BinaryPrerequisitesMarker.dat goto Error_MissingBinaryPrerequisites
if "%UE_USE_DOTNET%" == "1" (
echo Using Net Core for UBT
rem ## Verify that dotnet is present
call "%~dp0GetDotnetPath.bat"
if errorlevel 1 goto Error_NoDotnetSDK
REM ## Skip msbuild detection if using dotnet as this is done for us by dotnet-cli
goto :NoVsWhere
)
rem ## Get the path to MSBuild
call "%~dp0GetMSBuildPath.bat"
if errorlevel 1 goto Error_NoVisualStudioEnvironment
rem ## If we're using VS2017, check that NuGet package manager is installed. MSBuild fails to compile C# projects from the command line with a cryptic error if it's not:
rem ## https://developercommunity.visualstudio.com/content/problem/137779/the-getreferencenearesttargetframeworktask-task-wa.html
if not exist "%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" goto NoVsWhere
set MSBUILD_15_EXE=
for /f "delims=" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath') do (
if exist "%%i\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILD_15_EXE="%%i\MSBuild\15.0\Bin\MSBuild.exe"
goto FoundMsBuild15
)
)
:FoundMsBuild15
set MSBUILD_15_EXE_WITH_NUGET=
for /f "delims=" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere" -latest -products * -requires Microsoft.Component.MSBuild -requires Microsoft.VisualStudio.Component.NuGet -property installationPath') do (
if exist "%%i\MSBuild\15.0\Bin\MSBuild.exe" (
set MSBUILD_15_EXE_WITH_NUGET="%%i\MSBuild\15.0\Bin\MSBuild.exe"
goto FoundMsBuild15WithNuget
)
)
:FoundMsBuild15WithNuget
if not [%MSBUILD_EXE%] == [%MSBUILD_15_EXE%] goto NoVsWhere
if not [%MSBUILD_EXE%] == [%MSBUILD_15_EXE_WITH_NUGET%] goto Error_RequireNugetPackageManager
:NoVsWhere
rem Check to see if the files in the UBT directory have changed. We conditionally include platform files from the .csproj file, but MSBuild doesn't recognize the dependency when new files are added.
md ..\Intermediate\Build >nul 2>nul
dir /s /b Programs\UnrealBuildTool\*.cs >..\Intermediate\Build\UnrealBuildToolFiles.txt
if not exist ..\Platforms goto NoPlatforms
for /d %%D in (..\Platforms\*) do (
if exist %%D\Source\Programs\UnrealBuildTool dir /s /b %%D\Source\Programs\UnrealBuildTool\*.cs 2> nul >> ..\Intermediate\Build\UnrealBuildToolFiles.txt
)
:NoPlatforms
if not exist ..\Restricted goto NoRestricted
for /d %%D in (..\Restricted\*) do (
if exist %%D\Source\Programs\UnrealBuildTool dir /s /b %%D\Source\Programs\UnrealBuildTool\*.cs 2> nul >> ..\Intermediate\Build\UnrealBuildToolFiles.txt
)
:NoRestricted
fc /b ..\Intermediate\Build\UnrealBuildToolFiles.txt ..\Intermediate\Build\UnrealBuildToolPrevFiles.txt >nul 2>nul
if not errorlevel 1 goto SkipClean
copy /y ..\Intermediate\Build\UnrealBuildToolFiles.txt ..\Intermediate\Build\UnrealBuildToolPrevFiles.txt >nul
if "%UE_USE_DOTNET%" == "1" (
dotnet clean Programs\UnrealBuildTool\UnrealBuildToolCore.csproj -c Development
) else (
%MSBUILD_EXE% /nologo /verbosity:quiet Programs\UnrealBuildTool\UnrealBuildTool.csproj /property:Configuration=Development /property:Platform=AnyCPU /target:Clean
)
:SkipClean
if "%UE_USE_DOTNET%" == "1" (
dotnet build Programs\UnrealBuildTool\UnrealBuildToolCore.csproj -c Development
) else (
%MSBUILD_EXE% /nologo /verbosity:quiet Programs\UnrealBuildTool\UnrealBuildTool.csproj /property:Configuration=Development /property:Platform=AnyCPU /target:Build
)
if errorlevel 1 goto Error_UBTCompileFailed
rem ## Run UnrealBuildTool to generate Visual Studio solution and project files
rem ## NOTE: We also pass along any arguments to the GenerateProjectFiles.bat here
if "%UE_USE_DOTNET%" == "1" (
..\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.exe -ProjectFiles %*
) else (
..\Binaries\DotNET\UnrealBuildTool.exe -ProjectFiles %*
)
if errorlevel 1 goto Error_ProjectGenerationFailed
rem ## Success!
popd
exit /B 0
:Error_BatchFileInWrongLocation
echo.
echo GenerateProjectFiles ERROR: The batch file does not appear to be located in the /Engine/Build/BatchFiles directory. This script must be run from within that directory.
echo.
pause
goto Exit
:Error_MissingBinaryPrerequisites
echo.
echo GenerateProjectFiles ERROR: It looks like you're missing some files that are required in order to generate projects. Please check that you've downloaded and unpacked the engine source code, binaries, content and third-party dependencies before running this script.
echo.
pause
goto Exit
:Error_NoVisualStudioEnvironment
echo.
echo GenerateProjectFiles ERROR: Unable to find a valid installation of Visual Studio. Please check that you have Visual Studio 2017 or Visual Studio 2019 installed, and the MSBuild component is selected as part of your installation.
echo.
pause
goto Exit
:Error_RequireNugetPackageManager
echo.
echo UE5 requires the NuGet Package Manager to be installed to use %MSBUILD_EXE%. Please run the Visual Studio Installer and add it from the individual components list (in the 'Code Tools' category).
echo.
pause
goto Exit
:Error_NoDotnetSDK
echo.
echo GenerateProjectFiles ERROR: Unable to find a install of Dotnet SDK. Please make sure you have it installed and that `dotnet` is a globally available command.
echo.
pause
goto Exit
:Error_UBTCompileFailed
echo.
echo GenerateProjectFiles ERROR: UnrealBuildTool failed to compile.
echo.
pause
goto Exit
:Error_ProjectGenerationFailed
echo.
echo GenerateProjectFiles ERROR: UnrealBuildTool was unable to generate project files.
echo.
pause
goto Exit
:Exit
rem ## Restore original CWD in case we change it
popd
exit /B 1