Skip to content

Instantly share code, notes, and snippets.

@benvillalobos
Last active March 31, 2024 00:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benvillalobos/5edc77f51cf6a84a3859eb89a55c3729 to your computer and use it in GitHub Desktop.
Save benvillalobos/5edc77f51cf6a84a3859eb89a55c3729 to your computer and use it in GitHub Desktop.
Debugging Custom MSBuild Tasks

Debugging Custom MSBuild Tasks

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.

Steps

  1. Have VS open & breakpoint into your custom task.
  2. Open up a developer command prompt.
  3. cd your/project/directory
  4. 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.
  5. msbuild <your-project.csproj>
  6. On the prompt, choose your VS.
  7. Continue code execution, your breakpoint should hit.
    • If it's not hitting, make sure the task is being called from your project.

Relevant Links

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment