我想在我的测试中添加一个部署项。到目前为止,据我所知,路径是相对于解决方案的。我希望路径相对于项目。否则,该项目无法在多个解决方案中使用。
如何将部署项配置为相对于项目因变量?
我希望得到类似的东西:[DeploymentItem(@"$(ProjectDir)..\..\bin\$(Configuration)")]
但我没有找到任何文档,它似乎不起作用。
我只是做了一个小测试。只是简单的向导代码和一个部署项目:
[TestMethod]
[DeploymentItem("stdafx.cpp")]
void TestMethod1()
{
Assert::Fail();
};
并且 trx 文件显示以下行:
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'
这意味着“stdafx.cpp”是相对于解决方案目录(在 ...\depoymentItemTest 中)而不是项目目录(在 ...\depolymentItemTest\TestProject1 中)进行搜索的
最佳答案
我知道这是一个老问题,但我的回答可能对其他人有所帮助。
我能够通过两个简单的步骤解决这个问题:
xcopy /I /S /Y "$(TargetDir)*.*" "$(SolutionDir)\bin"
这会将项目文件夹的所有内容(包括子目录)复制到与解决方案相关的文件夹“bin”。
[DeploymentItem ("bin")]
这会将所有 bin 内容复制到测试文件夹
这种机制可以在构建事件和 DeploymentItem 中使用额外的过滤器进行改进(如果需要)
关于unit-testing - MsTest:如何设置相对于 $(ProjectDir) 或 $(OutDir) 的部署项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7230514/