Debugging aspects
Debugging the compile-time logic of an aspect can be challenging due to the compiler not executing your source code. Instead, the transformed code, derived from your source code, is stored under an unpredictable path.
Debugging compile-time logic
To debug compile-time logic, follow the steps below:
Insert breakpoints directly into your source code:
- In a build-time method such as
BuildAspect
, invoke Debugger.Break(). In a template method, invoke meta.DebugBreak().
Warning
Regular debugger breakpoints will not function. It is crucial to have a breakpoint embedded in your source code.
- In a build-time method such as
Attach the debugger to the process:
- In an aspect test, execute the test with the debugger.
To debug the compiler, set the
MetalamaDebugCompiler
property toTrue
during the build:dotnet build -p:MetalamaDebugCompiler=True
Debugging design-time logic
To attach a debugger to the design-time compiler process, follow these steps:
- Install the Metalama Command Line Tool as instructed in Installing the Metalama Command Line Tool.
Execute the command below:
metalama config edit diagnostics
In the
diagnostics.json
file, modify thedebugging/processes
section and enable debugging for the appropriate process. If you're using Visual Studio, this process is namedRoslynCodeAnalysisService
.{ // ... "debugger": { "processes": { "Rider": false, "RoslynCodeAnalysisService": true, "CodeLensService": false, "Other": false, "TestHost": false, "DevEnv": false, "OmniSharp": false, "BackstageWorker": false, "DotNetTool": false, "Compiler": false } } // ... }
Restart your IDE.