Building UE4 from source [error MSB3073 The command "..\..\Build\BatchFiles\Build.bat DatasmithSDK ...." exited with code 6

When building the whole solution of UE4 (tried 4.25 and 4.26) the following error comes up:

error MSB3073 The command "..\..\Build\BatchFiles\Build.bat DatasmithSDK Win64 Development -WaitMutex -FromMsBuild" exited with code 6. 

(Found solution, posting below)

1 Like

The short answer

I was silly enough to put the source code of my Unreal Engine under a path name containing a space character:

 C:\UnrealEngine 4.25\Engine\

Obviously that’s never a good idea. You can either avoid spaces and rebuild the whole solution or you have to patch DatasmithSDK.Target.cs as follows:

//C:\UE\Engine\Source\Programs\Enterprise\Datasmith\DatasmithSDK\DatasmithSDK.Target.cs
public void AddWindowsPostBuildSteps()
{
	// Copy the documentation
	string SrcPath = @"""$(EngineDir)\Source\Programs\Enterprise\Datasmith\DatasmithSDK\Documentation\*.*""";
	string DestPath = @"""$(EngineDir)\Binaries\$(TargetPlatform)\DatasmithSDK\Documentation\""";

	PostBuildSteps.Add(string.Format("echo Copying {0} to {1}", SrcPath, DestPath));
	PostBuildSteps.Add(string.Format("xcopy {0} {1} /R /Y /S", SrcPath, DestPath));

	// Copy the header files
	SrcPath = @"""$(EngineDir)\Source\Runtime\Datasmith\DatasmithCore\Public\*.h""";
	DestPath = @"""$(EngineDir)\Binaries\$(TargetPlatform)\DatasmithSDK\Public\""";

	PostBuildSteps.Add(string.Format("echo Copying {0} to {1}", SrcPath, DestPath));
	PostBuildSteps.Add(string.Format("xcopy {0} {1} /R /Y /S", SrcPath, DestPath));

	SrcPath = @"""$(EngineDir)\Source\Developer\Datasmith\DatasmithExporter\Public\*.h""";
	DestPath = @"""$(EngineDir)\Binaries\$(TargetPlatform)\DatasmithSDK\Public\""";

	PostBuildSteps.Add(string.Format("echo Copying {0} to {1}", SrcPath, DestPath));
	PostBuildSteps.Add(string.Format("xcopy {0} {1} /R /Y /S", SrcPath, DestPath));
}

Here I’m merely adding “” at the beginning and end of the strings SrcPath DestPath for this build script to handle path with spaces.

The long answer

Since it’s a good exercise I’ll explain how I found the fix for learning purposes, may this story help you solve other issues.

At first the error does not tell you much, if you analyze it, it says some script Build\BatchFiles\Build.bat failed and exited with error code 6. It may not even be clear what are the arguments if you are unfamiliar with UE.

So you might take a look at “C:\UE\Engine\Build\BatchFiles\Build.bat” and see it executes UnrealBuildTool.exe which means it’s actually UnrealBuildTool.exe which is failing and returning error code 6. The documentation says nothing about the meaning of code 6 so you may remember UE has its own build tool then look around and find C:\UE\Engine\Programs\UnrealBuildTool\Log.txt which contains the details of the last execution of UnrealBuildTool.exe by the look of the file’s timestamp:

//C:\UE\Engine\Programs\UnrealBuildTool\Log.txt
ParallelExecutor.ExecuteActions:   [46/46] Executing post build script (PostBuild-1.bat)
ParallelExecutor.ExecuteActions:   Copying C:\UE\Engine\Source\Programs\Enterprise\Datasmith\DatasmithSDK\Documentation\*.* to C:\UE\Engine\Binaries\Win64\DatasmithSDK\Documentation\
ParallelExecutor.ExecuteActions:   invalid number of parameters
ParallelExecutor.ExecuteActions:   Copying C:\UE\Engine\Source\Runtime\Datasmith\DatasmithCore\Public\*.h to C:\UE\Engine\Binaries\Win64\DatasmithSDK\Public\
ParallelExecutor.ExecuteActions:   invalid number of parameters
ParallelExecutor.ExecuteActions:   Copying C:\UE\Engine\Source\Developer\Datasmith\DatasmithExporter\Public\*.h to C:\UE\Engine\Binaries\Win64\DatasmithSDK\Public\
ParallelExecutor.ExecuteActions:   invalid number of parameters
UnrealBuildTool.Main: CompilationResultException: Error: OtherCompilationError
UnrealBuildTool.Main:    in UnrealBuildTool.ActionGraph.ExecuteActions(BuildConfiguration BuildConfiguration, List`1 ActionsToExecute) in C:\UE\Engine\Source\Programs\UnrealBuildTool\System\ActionGraph.cs:line 242
UnrealBuildTool.Main:    in UnrealBuildTool.BuildMode.Build(List`1 TargetDescriptors, BuildConfiguration BuildConfiguration, ISourceFileWorkingSet WorkingSet, BuildOptions Options, FileReference WriteOutdatedActionsFile) in C:\UE\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 372
UnrealBuildTool.Main:    in UnrealBuildTool.BuildMode.Execute(CommandLineArguments Arguments) in C:\UE\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 219
UnrealBuildTool.Main:    in UnrealBuildTool.UnrealBuildTool.Main(String[] ArgumentsArray) in C:\UE\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 550

Too focused about UnrealBuildTool.exe instead of researching the first error “invalid number of parameters” (which I should have) I only look at “UnrealBuildTool.Main: CompilationResultException: Error: OtherCompilationError” so now I know the return code 6 for UnrealBuildTool.exe means OtherCompilationError. I waste some more time and I go look at the code of UnrealBuildTool.exe in C:\UE\Engine\Source\Programs\UnrealBuildTool it’s C# and the entry point of the program is in UnrealBuildTool.cs I look for the word OtherCompilationError inside but it does not give me much info. I give up this lead.

Now, if I go back to visual studio and instead of looking at the Error List tab (which only gives me a very short and obscure message

error MSB3073 The command "..\..\Build\BatchFiles\Build.bat DatasmithSDK blabla" exited with code 6. 

I should have went straight to the detailed errors in the Output tab where it shows:

3>  [45/46] DatasmithSDK.target
3>  [46/46] Executing post build script (PostBuild-1.bat)
3>  Copying C:\UE\Engine\Source\Programs\Enterprise\Datasmith\DatasmithSDK\Documentation\*.* to C:\UE\Engine\Binaries\Win64\DatasmithSDK\Documentation\
3>  invalid number of parameters
3>  Copying C:\UE\Engine\Source\Runtime\Datasmith\DatasmithCore\Public\*.h to C:\UE\Engine\Binaries\Win64\DatasmithSDK\Public\
3>  invalid number of parameters
3>  Copying C:\UE\Engine\Source\Developer\Datasmith\DatasmithExporter\Public\*.h to C:\UE\Engine\Binaries\Win64\DatasmithSDK\Public\
3>  invalid number of parameters

Which is the same message I previously missed in the Unreal Build Tool Log.txt arf… It clearly says it’s attempting to copy some files from some location to another. It involves a project called “Datasmith” and if I look in the solution explorer of visual studio there is a project in programs/Datasmith/DatasmithSDK. I try to rebuild this specific project instead of the whole solution (the later is excruciating slow). Bingo, the error shows up again, well at least now I can quickly recompile this part and try various things. First I make sure files and folders are no read only. Recompiles … Nope. Then after some random search I figure out where this copy is specified: it’s in the build configuration file DatasmithSDK.Target.cs it’s calling the command xcopy and by the looks of it does not wrap the file paths with extra quotes and so it does not correctly parse file paths containing spaces! This is a mistakes I’ve made myself countless times aha! Hooray :slight_smile:

To summarize with this we’ve learned: how to find the build scripts of UE, where are the logs of Unreal Build Tool, overall get familiar with part of the folder structure of UE’s (modules and separate programs build tools) and pinpoint and only compile where the error comes from. But above all we’ve learned that we should better read the details of error messages… I could have went straight to where xcopy was just by looking up the string “Runtime\Datasmith\DatasmithCore\Public” if I had better read the error log and a bit of luck.

8 Likes

So what I did to solve this:

Ran the command that failed from the command prompt. This gave a more detailed error saying that it ran PostBuild-1.bat and that there was an invalid amount of parameters.

Located PostBuild-1.bat to \Engine\Intermediate\Build\Win64\DatasmithSDK\Development

Opened script in text editor, found the error to be that spaces in file paths weren’t accounted for. To fix this, add quotation marks around every file path on lines starting with “xcopy” and save the script.

1 Like

The long answer

Since it’s a good exercise I’ll explain how I found the fix for learning purposes, may this story help you solve other issues.

At first the error does not tell you much, if you analyze it, it says some script Build\BatchFiles\Build.bat failed and exited with error code 6. It may not even be clear what are the arguments if you are unfamiliar with UE.

So you might take a look at “C:\UE\Engine\Build\BatchFiles\Build.bat” and see it executes UnrealBuildTool.exe which means it’s actually UnrealBuildTool.exe which is failing and returning error code 6. The documentation says nothing about the meaning of code 6 so you may remember UE has its own build tool then look around and find C:\UE\Engine\Programs\UnrealBuildTool\Log.txt which contains the details of the last execution of UnrealBuildTool.exe by the look of the file’s timestamp:

Now, if I go back to visual studio and instead of looking at the Error List tab (which only gives me a very short and obscure message

error MSB3073 The command "..\..\Build\BatchFiles\Build.bat DatasmithSDK blabla" exited with code 6. 

I should have went straight to the detailed errors in the Output tab where it shows:

Which is the same message I previously missed in the Unreal Build Tool Log.txt arf… It clearly says it’s attempting to copy some files from some location to another. It involves a project called “Datasmith” and if I look in the solution explorer of visual studio there is a project in programs/Datasmith/DatasmithSDK. I try to rebuild this specific project instead of the whole solution (the later is excruciating slow). Bingo, the error shows up again, well at least now I can quickly recompile this part and try various things. First I make sure files and folders are no read only. Recompiles … Nope. Then after some random search I figure out where this copy is specified: it’s in the build configuration file DatasmithSDK.Target.cs it’s calling the command xcopy and by the looks of it does not wrap the file paths with extra quotes and so it does not correctly parse file paths containing spaces! This is a mistakes I’ve made myself countless times aha! Hooray :slight_smile:

To summarize with this we’ve learned: how to find the build scripts of UE, where are the logs of Unreal Build Tool, overall get familiar with part of the folder structure of UE’s (modules and separate programs build tools) and pinpoint and only compile where the error comes from. But above all we’ve learned that we should better read the details of error messages… I could have went straight to where xcopy was just by looking up the string “Runtime\Datasmith\DatasmithCore\Public” if I had better read the error log and a bit of luck.

Too focused about UnrealBuildTool.exe instead of researching the first error "invalid number of parameters" (which I should have) I only look at "UnrealBuildTool.Main: CompilationResultException: Error: OtherCompilationError" so now I know the return code 6 for UnrealBuildTool.exe means OtherCompilationError. I waste some more time and I go look at the code of UnrealBuildTool.exe in C:\UE\Engine\Source\Programs\UnrealBuildTool it’s C# and the entry point of the program is in UnrealBuildTool.cs I look for the word OtherCompilationError inside but it does not give me much info. I give up this lead.

This fixed the same error I was having. I don’t fully understand how triple quoting the paths resolves the space characters causing issues but I was able to compile because of this answer :slight_smile: Thanks for the informative take.

Good point about checking the Output tab! In my case the MSB3073 error was a due to a misspelling of an UPROPERTY parameter, that Visual Studio didn’t mark as an error.

Hey! Can any of you professionals lend me a hand? Kinda lost!

Build started…
1>------ Build started: Project: RetroFPS, Configuration: Development_Editor x64 ------
1>Running UnrealBuildTool: dotnet “……\Engine\Binaries\DotNET\UnrealBuildTool\UnrealBuildTool.dll” RetroFPSEditor Win64 Development -Project=“C:\Users\xxxx\Documents\UnrealProjects\RetroFPS\RetroFPS.uproject” -WaitMutex -FromMsBuild
1>Log file: C:\Users\xxxx\AppData\Local\UnrealBuildTool\Log.txt
1>Creating makefile for RetroFPSEditor (no existing makefile)
1>Parsing headers for RetroFPSEditor
1> Running Internal UnrealHeaderTool C:\Users\xxxx\Documents\UnrealProjects\RetroFPS\RetroFPS.uproject C:\Users\xxxx\Documents\UnrealProjects\RetroFPS\Intermediate\Build\Win64\RetroFPSEditor\Development\RetroFPSEditor.uhtmanifest -WarningsAsErrors -installed
1>C:\Users\xxxx\Documents\UnrealProjects\RetroFPS\Source\RetroFPS\RetroFPSAttributeSet.h(19): warning : The identifier ‘GENERATED_BODY’ was detected in a block being skipped. Was this intentional?
1>Total of 0 written
1>C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.MakeFile.Targets(44,5): error MSB3073: The command “D:\Games\UE_5.1\Engine\Build\BatchFiles\Build.bat RetroFPSEditor Win64 Development -Project=“C:\Users\xxxx\Documents\UnrealProjects\RetroFPS\RetroFPS.uproject” -WaitMutex -FromMsBuild” exited with code 6.
1>Done building project “RetroFPS.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Elapsed 00:06.949 ==========

Thank you very much. your post help me.