MSB4248 diagnostic code
This article describes the MSB4248 error code.
Message text
MSB4248: Cannot expand metadata in expression 'expression'.
Remarks
The MSB4248 error occurs when MSBuild is unable to expand item metadata in a build operation. This situation typically happens when metadata references are used in an invalid context or when the metadata being referenced doesn't exist for the item.
Possible causes
This error can be raised for the following reasons:
Metadata not supported for the item For example, referencing %(RootDir) on an item that isn't a path.
Dynamic item metadata in complex builds
- Dynamically generated item metadata may not always be available, depending on the build configuration.
Resolution
Validate that the requested metadata is consistent with the item.
Conditionally access metadata
For dynamic builds, ensure metadata is accessed conditionally to avoid referencing undefined metadata:
<Message Text="Target Framework: %(Metadataname)" Condition="'%(Metadataname)' != ''" />
Applies to
All versions of MSBuild