— New online course!  Azure App Services & App Service Security with ASP.NET Core — Special launch price 50% off —

Run tests from your TFS Team Build without a test list (.vsmdi) with code coverage


I got around to trying Buck Hodges’ power toy that lets you run unit tests in your Team Foundation Server (TFS) Team Build without having to use a test list (aka “.vsmdi” file). 

It works well but getting code coverage to run with it was kind of a trick.  There’s a post on forums.microsoft.com that discusses how to do it but — uhhh — it’s kind of hard to understand and — uhhh — didn’t work (exactly).  (The installation instructions for the power toy itself was super easy).

Here’s the process for getting it all working with code coverage.

Download the power toy zip and extract the contents to a directory on your Team Build Server.

Copy “Microsoft.TeamFoundation.PowerToys.Tasks.QualityTools.dll“ to “C:Program FilesMicrosoft Visual Studio 8Common7IDEPrivateAssemblies“.

Copy “Microsoft.TeamFoundation.Build.targets” to “C:Program filesMsBuildMicrosoftVisualStudiov8.0TeamBuild”.

Let’s assume that you have an existing Team Build (MSBuild) script you’re using to run a test list.  Open up the build script (TFSBuild.proj) and find the section that looks like this:

Change that section so that it looks like this:

The important part here is removing the “MetaDataFile“ block and adding the “TestContainerInOutput” block.  (I removed the extra code comments, too but this is optional.)

Ok.  This takes case of getting the unit tests executing.  Now we need to add support for code coverage.  Since code coverage is configured in a testrunconfig file, we need need to tell the msbuild/test engine which testrunconfig to load and where to get it (the file’s path).

Go back to the top of your MSBuild script and find the first “PropertyGroup” element.  It’ll probably start something like this:

Find the end of the PropertyGroup tag and add a reference to your testrunconfig before the closing “PropertyGroup“ tag:

Save your build script, check it in, and re-run your Team Build.  You should now be getting unit test and code coverage data without having to use a .vsmdi test list. 


One Response to "Run tests from your TFS Team Build without a test list (.vsmdi) with code coverage"
  1. Thanks so much for the detailed workaround description! Since you’re an MVP, would you consider re-posting this as a community content in Microsoft’s Knowledge Base? I believe this is quite an important workaround so it definitely belongs in there.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: