How can we display a “step” inside Visual Studio build process?

本小妞迷上赌 提交于 2019-12-21 11:31:37

问题


When you are monitoring the TFS build from Visual Studio (2008 or 2005), you can see where it is up to.

The issue is that I have some Post-Build custom steps I would like the developer to be able to see directly throught the UI. Those steps take some times and we can also get a "timing" of the build step.

Any idea how to have it displayed?


回答1:


This is the pattern that I normally use for adding steps to the build report in TFS 2008. (See http://code.msdn.microsoft.com/buildwallboard/ for the full example that I usually use in my Team Build talks)

Basically, the magic is that there is a custom task provided for you in TFS2008 called "BuildStep". Here is the section where I generate and MSI installer and build the appropriate build steps in the report:

  <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>

So initially, I create the build step and save the Id of the step in a propery called InstallerStepId. After I have performed my task, I set the status of that step to Succeeded. If any errors occur during the step then I set the status of that step to Failed.

Good luck,

Martin.




回答2:


Note that in @Martin Woodward's great example, PackageBinaries is one of the existing TFS build targets. If you want to use your own targets, you can use the CallTarget task to call them from one of the known targets, e.g.,

<Target Name="AfterDropBuild">
    <CallTarget Targets="CreateDelivery"/>
    <CallTarget Targets="CreateInventory"/>
</Target>

Then in your targets (e.g., CreateDelivery) use the BuildStep task as per Martin's example.



来源:https://stackoverflow.com/questions/226717/how-can-we-display-a-step-inside-visual-studio-build-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!