MsTest:如何设置相对于 $(ProjectDir) 或 $(OutDir) 的部署项
我想向我的测试添加一个部署项目。据我到目前为止的理解,路径是相对于解决方案的。我希望路径与项目相关。否则,该项目无法在多个解决方案中使用。 如何将部署项配置为与项目因变量相关?
我希望得到类似的东西: [DeploymentItem(@"$(ProjectDir)..\..\bin\$(Configuration)")]
但我没有找到任何文档,而且它没有似乎有效。
我刚刚做了一个小测试。只需简单的向导代码和一个部署项目:
[TestMethod]
[DeploymentItem("stdafx.cpp")]
void TestMethod1()
{
Assert::Fail();
};
并且 trx 文件显示以下行:
警告:测试运行部署问题:无法获取测试“TestProject1.UnitTest1.TestMethod1”指定的部署项“stdafx.cpp”的文件:System.IO.FileNotFoundException:找不到文件“d:\Development” \Projects\deploymentItemTest\stdafx.cpp'。 System.IO.FileNotFoundException:找不到文件“d:\Development\Projects\deploymentItemTest\stdafx.cpp”。 文件名:'d:\Development\Projects\deploymentItemTest\stdafx.cpp'
这意味着相对于解决方案目录(位于...\depoymentItemTest)而不是项目目录(位于在...\depolymentItemTest\TestProject1)
I want to add an deployment item to my test. As far as I understood up until now, the path is relative to the solution. I want the path to be relative to the project. Otherwise, the project can't be used in multiple solutions.
How can I configure the deployment Item to be relative to a project dependent variable?
I was hoping for something like: [DeploymentItem(@"$(ProjectDir)..\..\bin\$(Configuration)")]
but I don't find any documentation and it does not seem to work.
I just did a small test. Just plain wizard code and one deployment item:
[TestMethod]
[DeploymentItem("stdafx.cpp")]
void TestMethod1()
{
Assert::Fail();
};
and the trx file shows the following line:
Warning: Test Run deployment issue: Failed to get the file for deployment item 'stdafx.cpp' specified by the test 'TestProject1.UnitTest1.TestMethod1': System.IO.FileNotFoundException: Could not find file 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'.
System.IO.FileNotFoundException: Could not find file 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'.
File name: 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'
which means that "stdafx.cpp" is searched relative to the solution directory (which is in ...\depoymentItemTest) and not the project directory (which is in ...\depolymentItemTest\TestProject1)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道这是一个老问题,但我的回答可能对其他人有帮助。
我能够通过两个简单的步骤解决这个问题:
在测试项目上创建以下构建事件:
这会将项目文件夹的所有内容(包括子目录)复制到相对于解决方案的文件夹“bin”。
将以下 DeploymentItem 添加到测试类:
这会将所有 bin 内容复制到测试文件夹
此机制可以使用其他过滤器进行细化(如果需要)在构建事件和 DeploymentItem 中
I know this is an old question, but my answer may help others.
I was able to solve this problem with two simple steps:
Create the following build event on the test project:
This will copy all the contents (including sub-directories) of the project folder to a folder "bin" relative to the solution.
Add the following DeploymentItem to the test class:
This will copy all the bin contentes to the test folder
This mechanism may be refined (if required) with additional filters both in the build event and the DeploymentItem
让测试设置将文件复制到
Environment.CurrentDirectory
。Let the test setup copy the file to
Environment.CurrentDirectory
.