Debugging Code With Aspects
When debugging code that uses Metalama, by default, the debugger only shows you your original code, without the modifications applied by Metalama. This is convenient when you're using an existing aspect, but when you're developing an aspect, you want to be able to see the transformed code.
There are two options to debug the transformed code.
Option 1. Using the LamaDebug build configuration
The easiest option to debug the transformed code (instead of the source code) is to switch to the build configuration named LamaDebug
. This build configuration, besides the default Debug
and Release
configurations, is automatically defined for any project that imports the Metalama.Framework package.
To create a LamaDebug build configuration using Visual Studio:
- In the Build menu, choose Configuration Manager.
- In the Active solution configuration list box, choose
. Fill this dialog as follows:
- Name:
LamaDebug
(or your own name). - Copy settings from:
<Empty>
. Create new project configurations:
No
.
- Name:
Then, make sure that the solution configuration uses the project configuration named
LamaDebug
for each project that uses Metalama.
The benefit of this approach is that you can easily switch between source code and transformed code debugging.
Option 2. Setting properties manually
Alternatively, you can set the following MSBuild properties:
<PropertyGroup>
<MetalamaFormatOutput>True</MetalamaFormatOutput>
<MetalamaDebugTransformedCode>True</MetalamaDebugTransformedCode>
<MetalamaEmitCompilerTransformedFiles>True</MetalamaEmitCompilerTransformedFiles>
</PropertyGroup>
For details about these properties, see MSBuild Configuration Properties and Items.