我有一个 ItemGroup,并且在我的 MSBuild 项目中使用其元数据作为标识符进行批处理。例如:
<BuildStep
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Name="RunUnitTestsStep-%(TestSuite.Filename)-%(TestSuite.Extension)"
Message=" - Unit Tests: %(TestSuite.Filename): %(TestSuite.Extension)">
<Output
TaskParameter="Id"
PropertyName="RunUnitTestsStepId-%(TestSuite.Filename)-%(TestSuite.Extension)" />
</BuildStep>
但是,这不起作用,因为扩展中有一个点,它对于 Id 来说是无效字符(在 BuildStep 任务中)。因此,MSBuild 在 BuildStep 任务上总是失败。
我一直在尝试删除这个点,但没有成功。也许有一种方法可以将一些元数据添加到现有的 ItemGroup 中?理想情况下,我想要类似 %(TestSuite.ExtensionWithoutDot) 的内容。我怎样才能实现这一目标?
最佳答案
我认为您对 <Output>
的含义有点困惑元素在这里所做的 - 它将创建一个以 PropertyName 属性中的值命名的属性,并将该属性的 值 设置为来自构建步骤任务。您对 Id 的值没有影响 - 您只需将其存储在属性中以供以后引用,以便设置构建步骤的状态
考虑到这一点,我不明白为什么您担心创建的属性的名称将包含扩展名的串联。只要属性名称是唯一的,您就可以在后续的 BuildStep 任务中引用它,并且我认为您的测试套件文件名足以表明唯一性。
事实上,如果您进行目标批处理,则可以避免创建跟踪每个测试套件/构建步骤对的唯一属性:
<Target Name="Build"
Inputs="@(TestSuite)"
Outputs="%(Identity).Dummy">
<!--
Note that even though it looks like we have the entire TestSuite itemgroup here,
We will only have ONE - ie we will execute this target *foreach* item in the group
See http://beaucrawford.net/post/MSBuild-Batching.aspx
-->
<BuildStep
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Name="RunUnitTestsStep-%(TestSuite.Filename)-%(TestSuite.Extension)"
Message=" - Unit Tests: %(TestSuite.Filename): %(TestSuite.Extension)">
<Output
TaskParameter="Id"
PropertyName="TestStepId" />
</BuildStep>
<!--
..Do some stuff here..
-->
<BuildStep Condition=" Evaluate Success Condition Here "
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Id="$(TestStepId)"
Status="Succeeded" />
<BuildStep Condition=" Evaluate Failed Condition Here "
TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Id="$(TestStepId)"
Status="Failed" />
</Target>
关于msbuild - 如何在 MSBuild 中获取扩展名(不带点),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3459043/