buildmsbuilditemgroup

MsBuild Item function count does not work


I am running

  <ItemGroup>
    <TestItem Include="ITEM_VALUE"/>
    <TestItem Include="ITEM_VALUE2"/>
  </ItemGroup>
  <Target Name="test">
    <Message Text="@(TestItem->Count())"/>
  </Target>

Expecting to see "2" as the result

Error I'm getting instead:

Test.targets(5,5): error MSB4184: The expression ""ITEM_VALUE".Count()" cannot be evaluated. Method 'System.String.Count' not found.

Using .NET 4.0 MsBuild (Toolsversion 4.0)


Solution

  • Are you using a version of Visual Studio prior to 2012, or calling a version of MSBuild prior to the version installed with Visual Studio 2012 / .NET 4.5 upgrade? The Count item function is available beginning with MSBuild used in Visual Studio 2012. If your version of Visual Studio / MSBuild is older, you will not be able to call that function.