| Severity | Error |
| Reported by | Metalama.Framework |
| Message | Metalama is enabled in this project, but the METALAMA preprocessor symbol is not defined. This symbol is defined by Metalama.Framework.targets. Verify that the DefineConstants property is appended to and not overwritten. |
Cause
When a project references the Metalama.Framework package and the MetalamaEnabled property isn't False, the Metalama.Framework.targets file of the package appends the METALAMA symbol to the DefineConstants MSBuild property. Metalama relies on this symbol to recognize the projects it must process, and your code can use it in #if METALAMA directives.
Before it transforms the project, Metalama checks that the compilation defines the METALAMA symbol. If the symbol is missing, Metalama reports LAMA0053 and doesn't transform the project.
The usual cause is an MSBuild file evaluated after the package's targets that sets DefineConstants without including its previous value, for instance <DefineConstants>DEBUG;TRACE</DefineConstants> in a Directory.Build.targets file, in a custom target, or in the .targets file of another package. Setting DefineConstants in the project file itself is generally harmless, because the package's targets are evaluated after the project file and append the symbol again.
This diagnostic depends on the MSBuild configuration of the project, so it can't be shown in an example.
Resolution
- Find where the
DefineConstantsproperty is overwritten. You can generate a binary log withdotnet build -bland search forDefineConstantsin the MSBuild Structured Log Viewer, or rundotnet msbuild -pp:preprocessed.xmland search the preprocessed project. - Change the assignment so that it appends to the existing value instead of replacing it, for instance
<DefineConstants>$(DefineConstants);DEBUG;TRACE</DefineConstants>. - Rebuild the project.
If you don't want Metalama to process the project, set the MetalamaEnabled property to False instead.