A brief explanation on debugging msbuild tasks. Anything done on CLI (command-line interface) should be done in a Visual Studio Developer Command Prompt. If you have VS installed, search for "Developer command prompt."
This also works for dotnet
builds.
- Have VS open & breakpoint into your custom task.
- Open up a developer command prompt.
cd your/project/directory
set MSBUILDDEBUGONSTART=1
=1
: A prompt will appear when you build, choose what debugger to attach with.=2
: MSBuild will output a PID (process ID). Manually attach with a debugger, then press enter on cmd.
msbuild <your-project.csproj>
- On the prompt, choose your VS.
- Continue code execution, your breakpoint should hit.
- If it's not hitting, make sure the task is being called from your project.
- Tutorial: Creating a custom task. The most recent doc on writing tasks.
- Task Writing. A slightly older doc, but still useful.
- Creating an inline task. How to write a task directly into your project file!
- Debugging An MSBuild Build. For debugging into MSBuild itself.