2

我有一个 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>

但是,这不起作用,因为 Extension 中有一个点,它对于 Id 是无效字符(在 BuildStep 任务中)。因此,MSBuild 在 BuildStep 任务上总是失败。

我一直在尝试删除该点,但没有运气。也许有一种方法可以将一些元数据添加到现有的 ItemGroup 中?理想情况下,我想要类似 %(TestSuite.ExtensionWithoutDot) 的东西。我怎样才能做到这一点?

4

1 回答 1

3

我认为您对元素在这里所做的事情有些困惑<Output>——它将创建一个以 PropertyName 属性中的值命名的属性,并将该属性的设置为 BuildStep 任务的 Id输出值。您对 Id 的值没有影响 - 您只需将其存储在一个属性中以供以后参考,以便设置构建步骤的状态

考虑到这一点,我不明白您为什么担心创建的属性的名称会包含扩展名的串联。只要属性名称是唯一的,您可以稍后在后续的 BuildStep 任务中引用它,我认为您的测试套件文件名足以表明唯一性。

事实上,如果您进行了 Target 批处理,您可以避免创建跟踪每个测试套件/构建步骤对的唯一属性:

<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>
于 2010-08-12T09:20:01.057 回答