How To: Specify assemblies in TeamCity for MSTest build step

List test assemblies in TeamCity for MSTest build step

The approach to specify DLLs in build step in TeamCity  with a string pattern to be easily adopted for specific project.

I haven’t found  the way to specify assemblies for build step with something like %project_path%*.Tests.dll which would pick each assembly which matches to the pattern. So the only way is to specify the list in the List assembly files field of the step. I use TFS as a version control system and there is a special branch to build from.

The pattern can be looked like the following:


The real path could be as following in this case:


You can see that two types of variables are used. The built-in variable .build.checkoutDir specifies a checkout directory used for the build. In my case it is C:\BuildAgent\work\e573e7f3471f2689. The next two variables should be added by a user:

  • branch_name — this is the name of the branch to build, Trunk in my case.
  • build_configuration — this is the build configuration, Release in my case.

This approach removes a hard-code to the build environment and the setting can be easily shared between  agents, build configurations and branches. Just specify correct project.

Possible Issue with Packages

If you use a single repository for several solutions, then you may experience an issue with MSTest build step which embraces  tests from all solutions. It is because copy all assemblies used in tests into the same folder. In the case when several versions of the same assembly are used they all will be copied to the same location. This circumstance causes the issue with assembly ambiguous and TeamCity build fails.

In order to fix the issue you should divide the MSTest build by solutions. Each solution should have its own build configuration. This prevents the coping everything to the same location.


Leave a Reply

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

Related Post

%d bloggers like this: