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

試著忘記壹切 提交于 2019-12-12 17:03:07

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/10149705/in-msbuild-why-isnt-item-metadata-within-a-property-being-resolved

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!