1

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?

Community
  • 1
  • 1
Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148

1 Answers1

2

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.

Tomas Kubes
  • 23,880
  • 18
  • 111
  • 148
  • I love the answer. How do you do it from the command line? Thanks. – granadaCoder Apr 27 '16 at 20:50
  • Yes, either from command line or there there is "Working Directory" setting in TeamCity continuous integration which run the mstests.exe with every commit. – Tomas Kubes Apr 28 '16 at 07:49
  • 1
    Ok. You gave me the hint I needed. For future readers.........before I call MsTest.exe......I do a "CD .\FolderWhereMySolutionResides". Then on the DeploymentItem defintion, I have a relative path to the necessary file.....based on where .sln is (aka, the same FolderWhereMySolutionResides folder). Mine looked like this: [DeploymentItem(@".\packages\MyNugetPackage.1.2.3.4\lib\net45\SomeDll.dll")] – granadaCoder Apr 28 '16 at 14:44