Severity Code Description Project File Line Suppression State Error MSB4100 Expected "$([System.String]::Copy('%(Identity)').EndsWith('.resources.dll'))" to evaluate to a boolean instead of "$([System.String]::Copy('C:\Users\tarek\OneDrive\Desktop\StoreAp

م.طارق علي 0 Reputation points
2024-05-08T03:16:48.12+00:00

Severity Code Description Project File Line Suppression State

Error MSB4100 Expected "$([System.String]::Copy('%(Identity)').EndsWith('.resources.dll'))" to evaluate to a boolean instead of "$([System.String]::Copy('C:\Users\tarek\OneDrive\Desktop\StoreApi's\AllStoreApp\StoreClassLibrary\bin\Release\net8.0\StoreClassLibrary.dll').EndsWith('.resources.dll'))", in condition "!$([System.String]::Copy('%(Identity)').EndsWith('.resources.dll'))". StoreWeb C:\Program Files\dotnet\packs\Microsoft.NET.Runtime.WebAssembly.Sdk\8.0.3\Sdk\WasmApp.targets 339

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,816 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,672 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
4,142 questions
{count} votes

1 answer

Sort by: Most helpful
  1. دعاء علي حمدان الجروانية 0 Reputation points
    2025-06-14T15:59:41.8733333+00:00

    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.

    Feel free to copy and paste this directly. Would you also like the Arabic translation of this answer?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.