在MSBuild中创建字符串的ItemGroup [英] Create an ItemGroup of strings in MSBuild

查看:93
本文介绍了在MSBuild中创建字符串的ItemGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个任意字符串/名称的"ItemGroup",以便使用MSBuild转换,例如:

I want to create an "ItemGroup" of arbitrary strings / names in order to use MSBuild transforms, for example:

<ItemGroup>
    <Categories>First</Categories>
    <Categories>Second</Categories>
</ItemGroup>

然后我希望将这些类别的转换传递到控制台应用程序中,例如:

I then wish to pass a transform of these categories into a console app, e.g.:

/c @(Categories, ' /c ')

我在引号中说"ItemGroup"的原因是因为我不确定以这种方式使用ItemGroups是否适用于我-就我在文档中看不到的任何内容而言,ItemGroups 必须是文件,但是由于缺少必需的包含"属性,使用上述方法会导致错误消息.

The reason why I say "ItemGroup" in quotes, is because I'm not sure whether or not it is applicable for me to use ItemGroups in this way - as far as I can see nothing in the documentation states that ItemGroups must be files, however using the above results in an error message due to missing mandatory "Include" attribute.

  • 是否可以使用ItemGroups完成上述操作?
  • 或者,在不使用ItemGroups的情况下,还有一种更好的方法来实现上述目标吗?

推荐答案

您可以使用任意字符串以及Item中的文件,但是必须使用以下语法:

You can use arbitrary string as well as files in Item, but you must use this syntax :

<ItemGroup>
  <Categories Include="First"/>
  <Categories Include="Second"/>
</ItemGroup>

Item与任意字符串一起使用时,唯一的区别是某些元数据将毫无意义. (例如%(Categories.FullPath))

The only difference when you use Item with arbitrary string is that some metadata will be meaningless. (%(Categories.FullPath) for example)

然后,您可以使用Item来执行如下命令:

You can then use your Item to execute a command like this :

<Target Name="ExecCommand">
  <Exec Command="YourProgram.exe /c @(Categories, ' /c ')"/>

  <!-- Using transformation -->
  <Exec Command="YourProgram.exe @(Categories -> '/c %(Identity)')"/>
</Target>

这篇关于在MSBuild中创建字符串的ItemGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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