Debugging build.cs [c#] files

Hello,

I wonder there is any option to set break point in build.cs file.

Yes. Here are instructions for VS2019:

  1. Checkout the sources from github*.
  2. Set UnrealBuildTool as your StartUp project.
  3. Set the Debug arguments on UnrealBuildTool target to a valid build target. For example, I have a target named ShooterGameEditor.Target.cs, so I use -Target=“ShooterGameEditor Win64 Debug”
  4. Set your breakpoint in any Target.cs or Build.cs files you want to debug.
  5. Start the debugger.

** If you generate a VS project using a version of UE4 you installed from the Epic launcher, you won’t have the UnrealBuildTool target.*

2 Likes

Just to note, you don’t need a source engine build for this. UBT project and source files are included in launcher builds too, just open Engine/Source/Programs/UnrealBuildTool/UnrealBuildTool.csproj in Visual Studio.

Hello I do the same but can’t debug my build.cs could anyone help me please?

This is my logs:
‘UnrealBuildTool.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_64\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll’.
‘UnrealBuildTool.exe’ (CLR v4.0.30319: DefaultDomain): Loaded ‘C:\Program Files\Epic Games\UE_4.24\Engine\Binaries\DotNET\UnrealBuildTool.exe’. Symbols loaded.
‘UnrealBuildTool.exe’ (CLR v4.0.30319: UnrealBuildTool.exe): Loaded ‘C:\Program Files\Epic Games\UE_4.24\Engine\Binaries\DotNET\DotNETUtilities.dll’. Symbols loaded.
‘UnrealBuildTool.exe’ (CLR v4.0.30319: UnrealBuildTool.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll’.
‘UnrealBuildTool.exe’ (CLR v4.0.30319: UnrealBuildTool.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll’.
‘UnrealBuildTool.exe’ (CLR v4.0.30319: UnrealBuildTool.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll’.
‘UnrealBuildTool.exe’ (CLR v4.0.30319: UnrealBuildTool.exe): Loaded ‘C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll’.
UEBuildPlatformSDK.PrintSDKInfo: UnrealBuildTool.AndroidPlatformSDK has no valid SDK
UEBuildPlatformSDK.PrintSDKInfo: UnrealBuildTool.IOSPlatformSDK has no valid SDK
UEBuildPlatformSDK.PrintSDKInfo: UnrealBuildTool.LinuxPlatformSDK has no valid SDK
UEBuildPlatformSDK.PrintSDKInfo: UnrealBuildTool.WindowsPlatformSDK using manually installed SDK
BuildMode.Execute: Command line: “C:\Program Files\Epic Games\UE_4.24\Engine\Binaries\DotNET\UnrealBuildTool.exe” -Target=“TestPLuginEditor Win64 Debug”
BuildMode.CreateMakefile: Creating makefile for TestPLuginEditor (no existing makefile)
DynamicCompilation.RequiresCompilation: Compiling C:\Program Files\Epic Games\UE_4.24\Engine\Intermediate\Build\BuildRules\UE4Rules.dll: UnrealBuildTool.exe is newer
‘UnrealBuildTool.exe’ (CLR v4.0.30319: UnrealBuildTool.exe): Loaded ‘C:\Program Files\Epic Games\UE_4.24\Engine\Intermediate\Build\BuildRules\UE4Rules.dll’. Symbols loaded.
DynamicCompilation.RequiresCompilation: Compiling C:\Program Files\Epic Games\UE_4.24\Engine\Intermediate\Build\BuildRules\UE4ProgramRules.dll: UnrealBuildTool.exe is newer
‘UnrealBuildTool.exe’ (CLR v4.0.30319: UnrealBuildTool.exe): Loaded ‘C:\Program Files\Epic Games\UE_4.24\Engine\Intermediate\Build\BuildRules\UE4ProgramRules.dll’. Symbols loaded.
Exception thrown: ‘UnrealBuildTool.BuildException’ in UnrealBuildTool.exe
UnrealBuildTool.Main: ERROR: Couldn’t find target rules file for target ‘TestPLuginEditor’ in rules assembly ‘UE4Rules, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’.
UnrealBuildTool.Main: Location: C:\Program Files\Epic Games\UE_4.24\Engine\Intermediate\Build\BuildRules\UE4Rules.dll
UnrealBuildTool.Main: Target rules found:
UnrealBuildTool.Main: BuildException: Couldn’t find target rules file for target ‘TestPLuginEditor’ in rules assembly ‘UE4Rules, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’.
UnrealBuildTool.Main: Location: C:\Program Files\Epic Games\UE_4.24\Engine\Intermediate\Build\BuildRules\UE4Rules.dll
UnrealBuildTool.Main: Target rules found:
UnrealBuildTool.Main:
UnrealBuildTool.Main: at UnrealBuildTool.RulesAssembly.CreateTargetRules(String TargetName, UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, String Architecture, FileReference ProjectFile, CommandLineArguments Arguments) in C:\Program Files\Epic Games\UE_4.24\Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs:line 616
UnrealBuildTool.Main: at UnrealBuildTool.RulesAssembly.CreateTargetRules(String TargetName, UnrealTargetPlatform Platform, UnrealTargetConfiguration Configuration, String Architecture, FileReference ProjectFile, CommandLineArguments Arguments) in C:\Program Files\Epic Games\UE_4.24\Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs:line 617
UnrealBuildTool.Main: at UnrealBuildTool.UEBuildTarget.Create(TargetDescriptor Descriptor, Boolean bSkipRulesCompile, Boolean bUsePrecompiled) in C:\Program Files\Epic Games\UE_4.24\Engine\Source\Programs\UnrealBuildTool\Configuration\UEBuildTarget.cs:line 612
UnrealBuildTool.Main: at UnrealBuildTool.BuildMode.CreateMakefile(BuildConfiguration BuildConfiguration, TargetDescriptor TargetDescriptor, ISourceFileWorkingSet WorkingSet) in C:\Program Files\Epic Games\UE_4.24\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 433
UnrealBuildTool.Main: at UnrealBuildTool.BuildMode.Build(List`1 TargetDescriptors, BuildConfiguration BuildConfiguration, ISourceFileWorkingSet WorkingSet, BuildOptions Options, FileReference WriteOutdatedActionsFile) in C:\Program Files\Epic Games\UE_4.24\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 220
UnrealBuildTool.Main: at UnrealBuildTool.BuildMode.Execute(CommandLineArguments Arguments) in C:\Program Files\Epic Games\UE_4.24\Engine\Source\Programs\UnrealBuildTool\Modes\BuildMode.cs:line 192
UnrealBuildTool.Main: at UnrealBuildTool.UnrealBuildTool.Main(String] ArgumentsArray) in C:\Program Files\Epic Games\UE_4.24\Engine\Source\Programs\UnrealBuildTool\UnrealBuildTool.cs:line 520

Should TestPLuginEditor be TestPluginEditor? Not sure if it’s case-sensitive, but that’s the most obvious thing.

How, exactly how, does one perform this feat? These instructions from Doug_Richardson and kamrann, don’t really make sense.

I’m assuming I have a project all setup. I’m looking in the project within Visual Studio. Specifically I’m looking at a xxx.Build.cs file I’m interested in looking at in the debugger. The “Solution Explorer” shows myProject with three ‘folders’: Engine (including /UE4/Source/Programs/UnrealHeaderTool ), Games and Visualizers. There is no way to open up the UnrealHeaderTool from within my existing game Visual Studio instance.

I do see the UnrealBuildTool.csproj file that kamrann refers to, and I can open that project up in a separate Visual Studio window, but I don’t understand how to link that to the other instance of Visual Studio.

I’m confused by instructions #3) Set the Debug arguments on UnrealBuildTool target to a valid build target. For example, I have a target named ShooterGameEditor.Target.cs, so I use -Target=“ShooterGameEditor Win64 Debug” Where do you set those arguments?

I thought I was to use the Visual Studio (my second Visual Studio instance, the one with Unreal Build Tool) → Solution Explorer → Right Click on UnrealBuildTool → Properties → Debug → Start Project, Start Options -Target = "XXX Win64 Debug, Working Directory = the directory of my game project. Debug start. Total fail “1>CSC : error CS0006: Metadata file ‘C:\Program Files\Epic Games\UE_4.26\Engine\Source\Programs\DotNETCommon\DotNETUtilities\bin\HPD\Development\DotNETUtilities.dll’ could not be found”

Can someone explain? How do I step debug a C# xxx.Build.cs file?

Edit-------------------------------------------------------------------

got it… I figured this out from looking at the image that trongcongdn posted. You definitely do NOT want two instances of Visual Studio running. Instead, go to Solution Explorer, right click on empty space, add Existing Project, then point to the location mentioned above by kamrann. When that gets loaded, then update the properties page per what trongcongdn posted. thx to all for the info…

1 Like