✅
Answer to: MSB4100 – Expected Condition to Evaluate to Boolean
Hi,
Thank you for reporting this issue. Here’s an explanation of the problem and how you can resolve it.
⚠️
Error Summary:
You’re getting the following MSBuild error:
Error MSB4100: Expected "$([System.String]::Copy('%(Identity)').EndsWith('.resources.dll'))" to evaluate to a boolean instead of ...
This happens because the Condition attribute in your project file (or in a build target) is not evaluating to a Boolean (true/false) value as expected.
In your specific case, the condition:
!$([System.String]::Copy('%(Identity)').EndsWith('.resources.dll'))
is evaluating to a string instead of a Boolean, because MSBuild is trying to parse a literal path string that does not contain build metadata (%(Identity)) in the correct context.
🧠
Root Cause:
%(Identity) is an item metadata, and it should only be used inside ItemGroup or Target elements where an item (e.g., @(Reference), @(Content) etc.) is being iterated.
However, in your case, the MSBuild engine is seeing a raw file path instead of a valid item, so the expression becomes invalid and fails.
✅
Solution:
There are two possible solutions depending on your scenario:
🔧
Option 1: Use a Proper ItemGroup Context
Make sure that the condition using %(Identity) is inside a target that is iterating over items, for example:
<ItemGroup>
<MyAssemblies Include="@(ReferencePath)">
<IsNotResource>$([System.String]::Copy('%(Identity)').EndsWith('.resources.dll'))</IsNotResource>
</MyAssemblies>
</ItemGroup>
Then later you can do:
<Message Condition="'%(MyAssemblies.IsNotResource)' == 'false'" Text="Skipping resource assembly..." />
🔧
Option 2: Fix the Expression for a Single File Path
If you’re using a static path (like in your error message), then you don’t need metadata like %(Identity) at all. Instead, directly write:
Condition="!$([System.String]::Copy('$(MyFilePath)').EndsWith('.resources.dll'))"
Make sure $(MyFilePath) is defined earlier as a property:
<PropertyGroup>
<MyFilePath>C:\Users\tarek\OneDrive\Desktop\StoreApi's\AllStoreApp\StoreClassLibrary\bin\Release\net8.0\StoreClassLibrary.dll</MyFilePath>
</PropertyGroup>
Now the condition will properly evaluate to true or false.
✅
Summary:
- The MSB4100 error happens because MSBuild expects a Boolean condition but receives a string.
- This is often caused by incorrect use of %(Identity) outside of valid MSBuild item contexts.
- Fix it by either:
- Ensuring %(Identity) is used inside an item iteration, or
- Replacing it with a property like $(MyFilePath) if you’re using static paths.
- Let me know if you’d like help editing your .csproj file or inspecting the WasmApp.targets file for where the error is being triggered.
- Ensuring %(Identity) is used inside an item iteration, or
Feel free to copy and paste this directly. Would you also like the Arabic translation of this answer?