Open sandboxFocusImprove this doc

LAMA0080: The METALAMA_PROJECT_* preprocessor symbol is missing

Severity Warning
Reported by Metalama.Framework
Message Metalama is enabled in this project, but no METALAMA_PROJECT_* preprocessor symbol is defined. This symbol is defined by Metalama.Framework.targets and identifies the project uniquely. Without it, the IDE can confuse this project with another project of the solution that produces an assembly of the same name. Verify that the DefineConstants property is appended to and not overwritten.

Cause

The Metalama.Framework.targets file of the Metalama.Framework package appends two kinds of symbols to the DefineConstants MSBuild property:

  • METALAMA, which tells Metalama that it must process the project. When it's missing, Metalama reports LAMA0053.
  • METALAMA_PROJECT_<hash>, where the hash is computed from the path of the project relative to the solution directory, the target framework, the configuration, and the platform.

The IDE only sees the compilation of a project, not the project file, so Metalama identifies a project by its assembly name and by its preprocessor symbols. The METALAMA_PROJECT_<hash> symbol makes this identity unique. Without it, two projects of the solution that produce an assembly with the same name, for instance two Tests projects in different folders, look identical, and the design-time pipeline of one project can be used for the other.

Metalama reports LAMA0080 when it processes a project in an MSBuild build and the compilation defines METALAMA but no symbol starting with METALAMA_PROJECT_. The build itself is correct, which is why this is a warning and Metalama continues to transform the project. Only the experience in the IDE can be affected.

The usual cause is an MSBuild file evaluated after the package's targets that assigns DefineConstants without including its previous value but adds METALAMA back by hand, for instance <DefineConstants>DEBUG;TRACE;METALAMA</DefineConstants> in a Directory.Build.targets file or in a custom target. If the assignment doesn't add METALAMA back, Metalama reports LAMA0053 instead.

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>. You don't need to add METALAMA by hand: the package's targets define it.
  3. Rebuild the project, and restart the IDE if it still shows incorrect design-time results.

See also