简体   繁体   English

如何在MSTest中为DeploymentItem设置相对路径?

[英]How to set relative path for DeploymentItem in MSTest?

A lot of people struggle with relative path in DeploymentItem . 很多人都在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. 这仅在从Visual Studio运行时适用,因为mstest.exe是使用编译的项目(而不是sln文件)作为dll启动的,因此它无法正确确定部署项的相对路径。

I have found that I should set the DeploymentItem relative path in testrun.config by RelativePathRoot element. 发现我应该通过RelativePathRoot元素在testrun.config中设置DeploymentItem相对路径。 But there is almost no documentation for RelativePathRoot which is strange. 但是几乎没有关于RelativePathRoot的文档,这很奇怪。 How do you set relative path to MSTest ? 如何设置MSTest的相对路径?

The correct approach is to set the Working directory as solution directory when calling MSTest.exe. 正确的方法是在调用MSTest.exe时将工作目录设置为解决方案目录。 This is easy way how to resolve DeploymentItem problems. 这是解决DeploymentItem问题的简便方法。

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. 结果意味着,如果您的存储库中有多个项目和多个解决方案(每个解决方案都包含其中的一些项目),则所有这些解决方案(sln文件)必须位于同一目录中。 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. 因此,我强烈建议您在其中包含一个名为Solutions的根目录,并在其中包含所有这些sln文件。

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. 如果测试项目包含在不同目录中的两个不同解决方案中,则到DeploymentItem的相对路径将不同,并且您将永远不会在两个解决方案中都正确地使用DeploymentPath配置MSTest。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM