当我在 Visual Studio 上运行测试项目时,我使用下面的代码访问测试项目代码文件夹中的文件
var Location = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName
);
var FileLocation = Path.Combine(
Location
,@"..\..\..\TestProject1\App_Data\data.xml"
);
还有另一种(更好的)方法吗?
最佳答案
您是说您正在尝试在运行测试本身的上下文中查找文件?如果是这样,您应该查看 TestContext对象,特别是在 TestDeploymentDir属性(property)。您还应该将文件标记为 DeploymentItem .
关于c# - 如何打开测试项目代码文件夹中的文件? (Visual Studio 2008 和 .NET C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/451499/