Debugging Cake Build Scripts
This is going to be a quick post. I recently had some issues with a build.cake script and wanted to write a quick guide on how to debug them.
- Open a powershell window and navigate to the
build.cake
script. - From there, run the cake executable relative to where the build script is, for example:
.\tools\Cake\Cake.exe --debug
- The process id will be printed in the terminal for convenience.
- As far as I know it is not possible to set the target in debug mode. So before we go any further we need to make sure the default target is configured correctly.
RunTarget("Default");
Task("Default")
.IsDependentOn("Verify")
.IsDependentOn("Package")
.IsDependentOn("Deploy")
- Now open your debugger of choice, in this example I will be using Visual Studio 2017.
- In Visual Studio open your
build.cake
file. - Click “Attach…”.
- Select the “Cake.exe” process, reference the process id from step 3 if you can’t find the process.
- Once the debugger is attached you can add breakpoints and step through the script.
** Just a note that intellisense won’t work so you will have to use the immediate and local window to inspect variables.
I hope this quick tutorial was useful. Good luck and happy coding!