Open sandboxFocusImprove this doc

LAMA0053: The METALAMA preprocessor symbol is missing

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

  1. Find where the DefineConstants property is overwritten. You can generate a binary log with dotnet build -bl and search for DefineConstants in the MSBuild Structured Log Viewer, or run dotnet msbuild -pp:preprocessed.xml and search the preprocessed project.
  2. Change the assignment so that it appends to the existing value instead of replacing it, for instance <DefineConstants>$(DefineConstants);DEBUG;TRACE</DefineConstants>.
  3. Rebuild the project.

If you don't want Metalama to process the project, set the MetalamaEnabled property to False instead.

See also