How to set relative path for DeploymentItem in MSTest?

3k views Asked by At

A lot of people struggle with relative path in DeploymentItem. The relative path is from Solution Folder. This can only apply when run from Visual Studio, because mstest.exe is launched with compiled project (and not sln file) as dll and thus it cannot correctly determined the relative path of deployment item.

I have found that I should set the DeploymentItem relative path in testrun.config by RelativePathRoot element. But there is almost no documentation for RelativePathRoot which is strange. How do you set relative path to MSTest?

1

There are 1 answers

3
Tomas Kubes On BEST ANSWER

The correct approach is to set the Working directory as solution directory when calling MSTest.exe. This is easy way how to resolve DeploymentItem problems.

In consequences it means that if you have multiple projects and multiple solutions (every solution contains some of those projects) in you repository, that all these solution (sln files) MUST be in the same directory. Because the relative path from every any solution to one project must be same. So I strongly recommend to have one root directory named Solutions and all these sln files inside.

If the test project is contained in two different solutions in different directories, there will be different relative path to DeploymentItem and you will never configure MSTest with deploymentPath properly in both solutions.