The approach to specify DLLs in MSTest 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 MSTest 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 TeamCity variables are used. The built-in variable teamcity.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 TeamCity agents, build configurations and branches. Just specify correct project.
Possible Issue with NuGet Packages
If you use a single NuGet repository for several solutions, then you may experience an issue with MSTest build step which embraces tests from all solutions. It is because TeamCity 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.