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

Debugging MSBuild Tasks #8730

Merged
merged 6 commits into from
Feb 19, 2024
Merged

Commits on Feb 16, 2024

  1. Debugging MSBuild Tasks

    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.
    
    In the case of .NET Android we need to do a couple of thing first though. Firstly
    we need to disable the use of `ILRepacker` on the `Xamarin.Android.Build.Tasks`
    assembly. This is because `ILRepacker` does NOT handle debug symbols very well.
    Assemblies it generates seem to be JIT optimized so the debugger will not load
    the symbols. A new MSBuild property has been introduced to disable this feature
    while debugging. `_ILRepackEnabled` can be set as an environment variable which
    MSBuild will pickup.
    
    ```dotnetcli
    make prepare && _ILRepackEnabled=false make jenkins
    ```
    
    This will disable the `ILRepacker` for the build.
    
    You can then start your test app with the `dotnet-local` script (so it uses your build)
    
    ```dotnetcli
    MSBUILDDEBUGONSTART=2 ~/<some xamarin.android checkout>/dotnet-local.sh build -m:1
    ```
    
    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 Xamarin.Android.sln solution open. For VSCode open the workspace then use the `Debug MSBuild Task` Run and Debug option. You will be prompted for the PID and it will then connect.
    
    Once connection 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.
    dellis1972 committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    8eb6676 View commit details
    Browse the repository at this point in the history
  2. Update docs

    dellis1972 committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    ce859e6 View commit details
    Browse the repository at this point in the history
  3. more docs

    dellis1972 committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    5ef39fb View commit details
    Browse the repository at this point in the history
  4. Fix docs

    dellis1972 committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    6f180c0 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    88c3567 View commit details
    Browse the repository at this point in the history
  6. rename MacOS->Linux

    dellis1972 committed Feb 16, 2024
    Configuration menu
    Copy the full SHA
    26e3ff9 View commit details
    Browse the repository at this point in the history