Debugging Aspects
Debugging the compile-time logic of an aspect is currently difficult because the compiler does not execute your source code, but the transformed code produced from your source code and stored under an unpredictable path.
Debugging compile-time logic
To debug compile-time logic:
Inject breakpoints directly in your source code:
- In a build-time method such as
BuildAspect
, callSystem.Diagnostics.Debugger.Break()
. In a template method, call meta.DebugBreak.
Warning
Normal debugger breakpoints will not work. You must have a breakpoint directly in your source code.
- In a build-time method such as
Attach the debugger to the process
- In an aspect test, run the test with the debugger.
To debug the compiler, set the
MetalamaDebugCompiler
property toTrue
:dotnet build -p:MetalamaDebugCompiler=True
Debugging design-time logic
To attach a debugger to the design-time compiler process:
- Install Metalama Command Line Tools as described in Installing Metalama Command Line Tools.
Execute the following commands:
metalama config edit diagnostics
In the
diagnostics.json
file, edit thedebugging/processes
section and enable debugging for the proper process. If you are 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.