Add Helpers to aide Debugging MSBuild tasks #20695
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
One thing that is very useful is the ability to debug your Tasks while they are being run on a build process. This is possible thanks to the
MSBUILDDEBUGONSTART
environment variable. When set to2
this will force MSBuild to wait for a debugger connection beforecontinuing. You will see the following prompt.
You can then use VS or VSCode to attach to this process and debug you tasks.
This commit adds code helper tasks.json and launch.json entires to help make this debugging process a bit easier.
You can start your test app with the
dotnet-local
script (so it uses your maui build)Note: the
-m:1
is important as it restricts MSBuild to 1 node.Once MSBuild starts it will print the following
You need to copy the PID value so we can use this in the IDE. For Visual Studio you can use the
Attach to Process
menu option, while you have the Microsoft.Maui.sln solution open.For VSCode open the workspace then use the
Attach to Process
Run and Debug option. You will be prompted for the PID and it will then connect.Once connected go back to your command prompt and
press ENTER so that the MSBuild process can continue.
You will be able to set breakpoints in Tasks (but not Targets) and step through code from this point on.
If you want to test in-tree in VSCode the
Build Platform Sample
command will ask you if you want to debug MSBuild tasks and fill in theMSBUILDDEBUGONSTART
for you. The PID text will appear in theTerminal
window in VSCode. You can then use theAttach to Process
Run and Debug option to attach to the process.Issues Fixed
None. Quality of life improvements.