如何在Test Project代码文件夹中打开文件?(Visual Studio 2008和.NET C#)

Jad*_*ias 1 .net c# unit-testing visual-studio-2008 visual-studio

当我在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"
            );
Run Code Online (Sandbox Code Playgroud)

有另一种(更好的)方式吗?

cta*_*cke 5

你是说你试图在运行测试本身的上下文中找到该文件?如果是这样,您应该查看TestContext对象,特别是在TestDeploymentDir属性中.您还应该将该文件标记为DeploymentItem.