如果代码是为x86或任何CPU编译的,我的代码如何在运行时检测到

Arn*_*und 4 c# nunit unit-testing visual-studio-2010

我有很多集成测试可以读取文件的预期结果.我的测试通过相对路径访问这些文件.相对路径是x86与任何CPU的不同深度级别.例如,当我的测试在x86下运行时,他们需要读取以下文件"../../TestResults/MyTest.csv",但在任何CPU下他们需要访问"../TestResults/MyTest.csv"

到目前为止,我在每个测试夹具中都有以下常量:

   private const string platformDependentPrefix = "";
Run Code Online (Sandbox Code Playgroud)

如果我运行x86的测试,我需要在每个测试夹具中手动将""改为"../".

有没有办法实现自动化?

Teo*_*gul 5

非常hacky方式,但工作:

public static string Platform
{
    get 
    {
        if (IntPtr.Size == 8)
            return "x64";
        else
            return "x86";
    }
}
Run Code Online (Sandbox Code Playgroud)

您也可以进入CSharpProjectConfigurationProperties3.PlatformTarget酒店.