Open sandboxFocusImprove this doc

LAMA0084: The compile-time target frameworks are invalid

Severity Error
Reported by Metalama.Framework
Message The '<PropertyName>' MSBuild property has the value '<Value>', which is not valid because <Requirement>. Set this property to a list of target frameworks, separated by semicolons or commas, that meets this requirement.

Cause

To determine which APIs compile-time code can use, Metalama builds a small project of its own. The MetalamaCompileTimeTargetFrameworks MSBuild property sets the target frameworks of this project. Its default value, netstandard2.0;net8.0;net48, covers all runtimes that can host the compiler, so you only need to set it to remove target frameworks whose targeting packs you can't install.

Metalama splits the value of the property at semicolons and commas, and reports LAMA0084 when the resulting list doesn't meet one of these requirements:

  • It must include netstandard2.0, the framework against which compile-time code is compiled.
  • It must include a target framework that matches the runtime that hosts the compiler: a .NET 6.0 or later framework, such as net8.0, when the compiler runs on .NET, for instance with dotnet build, or a .NET Framework 4.x framework, such as net48, when it runs on .NET Framework, for instance in Visual Studio or with MSBuild.exe.

In the message, <PropertyName> is the name of the property, <Value> is its value after splitting, rejoined with semicolons, and <Requirement> is the requirement that isn't met. A value whose target frameworks are separated by spaces is read as a single, unknown framework, so it fails too.

This diagnostic depends on an MSBuild property, so it can't be shown in an example.

Resolution

  • Remove the MetalamaCompileTimeTargetFrameworks property from your project or Directory.Build.props file to use the default value. This is the recommended option.
  • If you need a custom value, include netstandard2.0 and a target framework for each runtime that builds your project, separated by semicolons, for instance <MetalamaCompileTimeTargetFrameworks>netstandard2.0;net8.0;net48</MetalamaCompileTimeTargetFrameworks>. Omit net48 only if your project is never built on .NET Framework, that is, by Visual Studio or MSBuild.exe.

See also