You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add Helpers to aide Debugging MSBuild tasks (dotnet#20695)
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.
Note: the `-m:1` is important as it restricts MSBuild to 1 node.
341
+
342
+
Once MSBuild starts it will print the following
343
+
344
+
```dotnetcli
345
+
Waiting for debugger to attach (dotnet PID xxxx). Press enter to continue...
346
+
```
347
+
348
+
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.
349
+
350
+
Once connected go back to your command prompt and press ENTER so that the MSBuild process can continue.
351
+
352
+
You will be able to set breakpoints in Tasks (but not Targets) and step through code from this point on.
353
+
354
+
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.
0 commit comments