Creating link to TFS Reports in build script

Posted by Marcus Hammarberg on August 7, 2008
Stats
For a few days (on and off, not continously) I've been searching the net for some way to present code coverage data in a nice way. That is - when our build script is running tests under code coverage we don't present the code coverage result.

The code coverage data is located in the TRX-file generated by MSTest. And there is a great tool, trx2html, that I've already blogged about. But that tool doesn't show the any code coverage result.

Here I must add that I know these two things:
  • firstly the main part of the code coverage data is only interesting to the developers and might not benefit from being shown to others.
    But I just want to show that 97% of our code is covered by out unit test. Calms the project management...
  • secondly - it might be a simple thing to tweak the internal XML Transformation of the trx2html-tool.
    But it doesn't feel good to have tweaked third party code in a professional environment.

OK - after a long while I realized that TFS is, out of the box, giving us some reports. One of the is called Builds and simply shows a list of all builds, with code coverage data in place.

So I ran that report, which opens in the browser, and it did the trick; it shows the right amount of data at a reasonable level.

Now I just needed to create a link to the report and put it in the drop-folder for our build so that all persons interested could see the latest results. Here is what I did - not pretty, but it works;

  • I browsed to the report and dragged the link (the little icon in the url-field) to my desktop
  • I opened that "Internet shortcut" in Notepad and copied the entier content
  • Then I added a txt-file to my solution and pasted the content of the Internet shortcut into that file.
    For some reason you can't add a Internet shortcut to the solution.
  • Then I created a MSBuild target that copies the file to the drop location and change its file-extension to .url.
    Here is my target:

<!-- Target that creates a link to the builds report -->
<Target Name="SkapaLankTillByggRapporten">
<BuildStep TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
BuildUri="$(BuildUri)"
Name="CreateLinkFileToBuildReport"
Message="Create link to build report"
Status="Succeeded" />
<Message Text="Create link to build report" />

<Copy SourceFiles="$(SolutionRoot)\Solution Items\Tools\BuildReportLink.txt" DestinationFiles="\\$(DropServerName)\Drops\$(AppName)\TestResults\BuildReportLink.url" />
</Target>

  • Finally I made my build script call that target

As I said - maybe not a very pretty solution but it sure came through for us and helped us report code coverage data in a nice way.

Oops - almost forgot... To reconnect to the title of this post. This "technique" can of course be applied to any report in TFS or other URL-addressable resources.



Published by Marcus Hammarberg on Last updated