Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Helpers to aide Debugging MSBuild tasks #20695

Merged
merged 1 commit into from
Apr 8, 2024

Conversation

dellis1972
Copy link
Contributor

@dellis1972 dellis1972 commented Feb 19, 2024

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 to 2 this will force MSBuild to wait for a debugger connection before
continuing. You will see the following prompt.

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)

MSBUILDDEBUGONSTART=2 ~/<some maui checkout>/dotnet-local.sh build -m:1
MSBUILDDEBUGONSTART=2 ~/<some maui checkout>/dotnet-local.sh build -m:1
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

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.

Issues Fixed

None. Quality of life improvements.

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.
@rmarinho rmarinho merged commit 1d69366 into dotnet:main Apr 8, 2024
43 of 47 checks passed
@dellis1972 dellis1972 deleted the msbuildtaskddebug branch April 8, 2024 12:03
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.
@github-actions github-actions bot locked and limited conversation to collaborators May 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants