Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MSTest VS2010-DeploymentItem将文件复制到不同计算机上的不同位置_C#_Unit Testing_Testing_Mstest_Deploymentitem - Fatal编程技术网

C# MSTest VS2010-DeploymentItem将文件复制到不同计算机上的不同位置

C# MSTest VS2010-DeploymentItem将文件复制到不同计算机上的不同位置,c#,unit-testing,testing,mstest,deploymentitem,C#,Unit Testing,Testing,Mstest,Deploymentitem,我找到了DeploymentItem [TestClass(), DeploymentItem(@"TestData\")] 在不同的计算机上生成和运行测试时,未将测试数据文件复制到同一位置 测试数据文件被复制到我机器上测试项目中的“bin\debug”目录,但在我朋友的机器上,它们被复制到“TestResults\name_machine YY-MM-DD HH_MM_SS\Out” 我的计算机上的bin\debug目录可以通过以下代码获得: string appDirectory = P

我找到了DeploymentItem

[TestClass(), DeploymentItem(@"TestData\")]
在不同的计算机上生成和运行测试时,未将测试数据文件复制到同一位置

测试数据文件被复制到我机器上测试项目中的“bin\debug”目录,但在我朋友的机器上,它们被复制到“TestResults\name_machine YY-MM-DD HH_MM_SS\Out”

我的计算机上的bin\debug目录可以通过以下代码获得:

string appDirectory = 
Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
同样的代码将在我的朋友电脑上返回
TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out

然而,这并不是真正的问题。问题是我制作的测试数据文件有一个文件夹结构,只有在复制到bin\debug时,这个文件夹结构才在我的机器上保持,而在我的朋友机器上,只有文件被添加到
TestResults\*name_machine YY-MM-DD HH_MM_SS*\Out
目录中。这意味着测试将在我的机器上通过,而在他的机器上失败


是否有办法确保DeploymentItem始终复制到bin\debug文件夹?或者一种确保在DeploymentItem将文件复制到
TestResults\*name\u machine YY-MM-DD HH\u MM\u SS*\Out
folder?

一段时间后,最好的处理方法是确保每个子目录,添加新的DeploymentItem,确保指定“outputDirectory”,如下所示:

[TestClass(), DeploymentItem("TestData\\", "TestData"),
DeploymentItem(@"TestData\\SubDir\\", "TestData\\SubDir")]

这可以让测试在你的机器上运行-希望这对别人有帮助

这正好解决了我的相对路径问题。对于存储在子文件夹中的文件和app.config文件中定义的相对路径,我也有同样的问题。thx
DeploymentItem
属性仅针对方法。你写的东西到底怎么样?