Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MSBuild, why isn't Item Metadata, within a property, being resolved?

Tags:

msbuild

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.

like image 718
Craig Avatar asked Nov 20 '25 03:11

Craig


1 Answers

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

like image 198
Ritch Melton Avatar answered Nov 22 '25 04:11

Ritch Melton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!