使用MSBuild,如何通过迭代ItemGroup中的文件来构造动态字符串? [英] Using MSBuild, how to construct a dynamic string from iterating over files in an ItemGroup?

查看:42
本文介绍了使用MSBuild,如何通过迭代ItemGroup中的文件来构造动态字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建多个/testcontainer:参数以馈入执行MsTest的任务.

I need to create multiple /testcontainer: parameters to feed into a task that exec's MsTest.

我有以下内容:

  <ItemGroup>
    <TestFiles Include="$(ProjectPath)\**\UnitTest.*.dll" />
  </ItemGroup>

对于 TestFiles 中的每个匹配,我想构建一个像这样的字符串:

for each match in TestFiles I would like to build a string like so:

"/testcontainer:UnitTest.SomeLibrary1.dll"
"/testcontainer:UnitTest.SomeLibrary2.dll"
"/testcontainer:UnitTest.SomeLibrary3.dll"

我试图使用MSBuild的内部结构而不必创建自定义任务,这可能吗?

I am trying to use the internals of MSBuild without having to create a custom task, is this possible ?

TIA

推荐答案

这确实取决于此后的用法.例如,您要发送给它的任务,它是否在项目列表中接受,并且您想一次或多次调用它?

It really depends on the usage of this afterwards. For example the task that you are sending it to, does it accept in an item list and do you want to invoke it once or multiple times?

如果要调用一次,则可以使用@(...)语法,如果要多次调用,则可以使用%(...)语法进行批处理.

If you want to invoke it once then you use the @(...) syntax, and if you want to invoke it many times then you do batching with the %(...) syntax.

要调用一次

<Message Text="Test Files: @(TestFiles->'/testcontainer:%(RecursiveDir)%(Filename)%(Extension)')"/>

要多次调用

<Message Text="Test Files: /testcontainer:%(TestFiles.RecursiveDir)%(TestFiles.Filename)%(TestFiles.Extension)"/>

有关批处理的更多信息,请访问 http://sedotech.com/Resources#batching

More info on batching at http://sedotech.com/Resources#batching

这篇关于使用MSBuild,如何通过迭代ItemGroup中的文件来构造动态字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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