Add Helpers to aide Debugging MSBuild tasks#20695
Merged
Merged
Conversation
1a7fd14 to
b6cb91b
Compare
b6cb91b to
544c205
Compare
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 to `2` this will force MSBuild to wait for a debugger connection before continuing. You will see the following prompt. ```dotnetcli Waiting for debugger to attach (dotnet PID 13001). Press enter to continue... ``` 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) ```dotnetcli MSBUILDDEBUGONSTART=2 ~/<some maui checkout>/dotnet-local.sh build -m:1 ``` ```dotnetcli MSBUILDDEBUGONSTART=2 ~/<some maui checkout>/dotnet-local.sh build -m:1 ``` ```dotnetcli set MSBUILDDEBUGONSTART=2 ~/<some maui checkout>/dotnet-local.cmd build -m:1 ``` --- Note: the `-m:1` is important as it restricts MSBuild to 1 node. Once MSBuild starts it will print the following ```dotnetcli Waiting for debugger to attach (dotnet PID xxxx). Press enter to continue... ``` 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 the `MSBUILDDEBUGONSTART` for you. The PID text will appear in the `Terminal` window in VSCode. You can then use the `Attach to Process` Run and Debug option to attach to the process.
544c205 to
9b5dd5d
Compare
rmarinho
approved these changes
Apr 8, 2024
mattleibow
added a commit
that referenced
this pull request
Apr 10, 2024
After this PR: #20695 We now need to add MAUI back in there. It was not needed before because if it was blank it was assumed maui. Now it is more than just MAUI.
rmarinho
pushed a commit
that referenced
this pull request
Apr 10, 2024
After this PR: #20695 We now need to add MAUI back in there. It was not needed before because if it was blank it was assumed maui. Now it is more than just MAUI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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
MSBUILDDEBUGONSTARTenvironment variable. When set to2this 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-localscript (so it uses your maui build)Note: the
-m:1is 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 Processmenu option, while you have the Microsoft.Maui.sln solution open.For VSCode open the workspace then use the
Attach to ProcessRun 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 Samplecommand will ask you if you want to debug MSBuild tasks and fill in theMSBUILDDEBUGONSTARTfor you. The PID text will appear in theTerminalwindow in VSCode. You can then use theAttach to ProcessRun and Debug option to attach to the process.Issues Fixed
None. Quality of life improvements.