2

Below is a portion of a MSBuild file that I'm working on:

<ItemGroup>
  <Tests Include="$(SolutionDir)\**\bin\$(TestPlatform)\$(Configuration)\*.Tests.dll" />
</ItemGroup>

<PropertyGroup>
  <TestProperties>/testcontainer:%(Tests.FullPath)</TestProperties>
</PropertyGroup>

I want to have a property that holds a command line switch. However, when I try to use $(TestProperties) in an Exec Command string, %(Tests.FullPath) is never resolved to the absolute path of the Tests item. Instead, it's always processed literally, as "%(Tests.FullPath)".

Am I doing something wrong or is this a standard MSBuild behavior? If the latter, is there a way for me to workaround this?

Thanks

P.S. - I realize I probably don't need to access the FullPath property since my Include value is an absolute path. However, I'd still like to understand the issue, along with how to handle it.

Craig
  • 1,890
  • 1
  • 26
  • 44

1 Answers1

7

You have a syntax error. Item lists are referenced via the @ character and item meta data is referenced via %. Reference the MSBuild Special Character Reference for details. To access the well known item metadata, you need to apply a transform inside the Property itself.

<ItemGroup>
  <Tests Include="MyFile.txt" />
</ItemGroup>

<PropertyGroup>
  <TestProperties>/testcontainer:@(Tests->'%(FullPath)')</TestProperties>
</PropertyGroup>

You can find more help here

Ritch Melton
  • 11,498
  • 4
  • 41
  • 54
  • Except this doesn't work either: "Item lists cannot be concatenated with other strings where an item list is expected. Use a semicolon to separate multiple item lists." – David Nelson Feb 13 '15 at 18:05
  • I have no idea what you are talking about. This resolves item metadata like the OP asked. – Ritch Melton Feb 13 '15 at 19:56
  • It does, but only if used inside a target. Outside of a target, it produces the error I posted. – David Nelson Feb 16 '15 at 18:28
  • That makes sense, the evaluation phase of msbuild would assign the content, but not the result. The execution phase, where targets get executed, would cause the expansion to happen and the results of that expansion placed into the item. – Ritch Melton Feb 16 '15 at 18:38