在MSBuild中,为什么不解析属性内的项目元数据? [英] In MSBuild, why isn't Item Metadata, within a property, being resolved?

查看:70
本文介绍了在MSBuild中,为什么不解析属性内的项目元数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我正在处理的 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>

我想拥有一个包含命令行开关的属性.但是,当我尝试在 Exec Command 字符串中使用$(TestProperties)时,%(Tests.FullPath)从未解析为Tests项的绝对路径.取而代之的是,它总是按字面意义被处理为"%(Tests.FullPath)".

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)".

我做错什么了吗?这是标准的 MSBuild 行为吗?如果是后者,我有办法解决此问题吗?

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

谢谢

P.S. -我意识到我可能不需要访问FullPath属性,因为我的Include值是绝对路径.但是,我仍然想了解这个问题以及如何处理它.

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.

推荐答案

您遇到语法错误.项目列表通过@字符引用,项目元数据通过%引用.有关详细信息,请参考 MSBuild特殊字符参考.要访问众所周知的项目元数据,您需要在属性本身内部应用转换.

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>

您可以在此处

这篇关于在MSBuild中,为什么不解析属性内的项目元数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆