如何在 Visual Studio 的构建过程中显示“步骤”?

7

当你从Visual Studio(2008或2005)监视TFS构建时,你可以看到它进行到哪一步了。

问题在于,我有一些后期构建自定义步骤,我希望开发人员能够直接通过UI查看。这些步骤需要一些时间,我们也可以获得构建步骤的“时间”。

有什么想法可以显示它吗?

2个回答

9
这是我通常在TFS 2008中添加构建报告步骤的模式。(请参见http://code.msdn.microsoft.com/buildwallboard/,其中包含我在团队构建演讲中通常使用的完整示例)
基本上,奇迹就在于TFS2008为您提供了一个名为"BuildStep"的自定义任务。以下是我生成MSI安装程序并在报告中构建适当的构建步骤的部分:
  <Target Name="PackageBinaries">

    <!-- create the build step -->
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
               BuildUri="$(BuildUri)"
               Message="Creating Installer"
               Condition=" '$(IsDesktopBuild)' != 'true' " >
      <Output TaskParameter="Id"
              PropertyName="InstallerStepId" />
    </BuildStep>

    <!-- Create the MSI file using WiX -->
    <MSBuild Projects="$(SolutionRoot)\SetupProject\wallboard.wixproj"
  Properties="BinariesSource=$(OutDir);PublishDir=$(BinariesRoot);Configuration=%(ConfigurationToBuild.FlavourToBuild)" >
    </MSBuild>

    <!-- If we sucessfully built the installer, tell TFS -->
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
               BuildUri="$(BuildUri)"
               Id="$(InstallerStepId)"
               Status="Succeeded"
               Condition=" '$(IsDesktopBuild)' != 'true' " />

    <!-- Note that the condition above means that we do not talk to TFS when doing a Desktop Build -->

    <!-- If we error during this step, then tell TFS we failed-->
    <OnError   ExecuteTargets="MarkInstallerFailed" />
  </Target>

  <Target Name="MarkInstallerFailed">
    <!-- Called by the PackageBinaries method if creating the installer fails -->
    <BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
               BuildUri="$(BuildUri)"
               Id="$(InstallerStepId)"
               Status="Failed"
               Condition=" '$(IsDesktopBuild)' != 'true' " />
  </Target>

首先,我创建了构建步骤,并将步骤的ID保存在名为InstallerStepId的属性中。完成任务后,我将该步骤的状态设置为“成功”。如果在执行步骤期间发生任何错误,则将该步骤的状态设置为“失败”。

祝好运,

Martin.


0
请注意,在@Martin Woodward的示例中,PackageBinaries是现有的TFS构建目标之一。如果您想使用自己的目标,可以使用CallTarget任务从已知目标之一调用它们,例如:
<Target Name="AfterDropBuild">
    <CallTarget Targets="CreateDelivery"/>
    <CallTarget Targets="CreateInventory"/>
</Target>

然后在您的目标(例如CreateDelivery)中,按照Martin的示例使用BuildStep任务。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接