1

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)

1 Answers1

4

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.

Michael
  • 1,272
  • 1
  • 9
  • 18
  • I'm using MsBuild 4.0, which according to [MSDN](http://msdn.microsoft.com/en-us/library/ee886422.aspx) is the version where item functions were added. – Kent Aleksandrov Sep 25 '13 at 08:14
  • 1
    If you look at the MSDN link provided above, it shows the `Count` function available starting with VS 2012 (MSBuild for VS 2012, .NET 4.5). If you look at the link for [VS 2010](http://msdn.microsoft.com/en-us/library/ee886422(v=vs.100).aspx) (MSBuild for VS 2010, .NET 4.0), however, you'll notice that the `Count` function is not included in the list of item functions. – Michael Sep 25 '13 at 14:01
  • You're absolutely right, but the weirdest thing is that i managed to get it working on my local machine using 4.0 and Visual Studio 2010. I think it's down to .net 4.5 being installed on my machine even though I am using 4.0 version to run it. A bit strange buy hey. thank you at least now I understand that – Kent Aleksandrov Sep 26 '13 at 11:10