我尝试从 SVN 预提交挂钩内的控制台应用程序调用 MSTest,但出现错误?

发布于 2024-09-24 05:15:36 字数 1460 浏览 0 评论 0原文

我试图从一个简单的控制台应用程序调用 MSTest.exe,该应用程序是从 SVN 预提交挂钩内部执行的。

如果我使用 TortoiseSVN 提交,它会自动运行下面的控制台应用程序代码。

(跳过代码看看会发生什么...)

// 代码

static void Main(string[] args)
{
    string testPath = @"C:\Users\myname\Documents\SVN\Test\bin\Debug\TestProject1.dll";

    string mstest = GetMSTestOutput(testPath);

    if (mstest != null)
    {
        Console.Error.WriteLine(mstest);
        Environment.Exit(1);  // I WANT it to stop here, so I can see output while testing
    }
}

private static string GetMSTestOutput(string testPath)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
    FileName = @"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe",
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    Arguments = String.Format("/testcontainer:{0}", testPath)
};

Process process = Process.Start(processStartInfo);
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
 return output;
}

// 输出

这是我在 TortoiseSVN 窗口中看到的内容:

错误:提交失败(详细信息如下):
错误:提交被预提交挂钩阻止(退出代码 1),输出为:
错误:Microsoft (R) 测试执行命令行工具版本 10.0.30319.1
错误:版权所有 (c) Microsoft Corporation。保留所有权利。
错误:
错误:文件
错误:“C:\Users\myname\Documents\SVN\Test\bin\Debug\TestProject1.dll”
错误:未找到。

所以你可以看到我正确调用 MSTest,但它声称路径错误。

但是,如果我手动打开 VS 命令提示符并键入完全相同的路径,则代码运行不会出现错误。

我做错了什么?

I am trying to call MSTest.exe from a simple console app that is executed from inside an SVN pre-commit hook.

If I use TortoiseSVN to Commit, it auto-runs the console app code below.

(skip after the code to see what happens...)

// CODE

static void Main(string[] args)
{
    string testPath = @"C:\Users\myname\Documents\SVN\Test\bin\Debug\TestProject1.dll";

    string mstest = GetMSTestOutput(testPath);

    if (mstest != null)
    {
        Console.Error.WriteLine(mstest);
        Environment.Exit(1);  // I WANT it to stop here, so I can see output while testing
    }
}

private static string GetMSTestOutput(string testPath)
{
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
    FileName = @"C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe",
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
    Arguments = String.Format("/testcontainer:{0}", testPath)
};

Process process = Process.Start(processStartInfo);
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
 return output;
}

// OUTPUT

This is what I see in the TortoiseSVN window:

Error: Commit failed (details follow):
Error: Commit blocked by pre-commit hook (exit code 1) with output:
Error: Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Error: Copyright (c) Microsoft Corporation. All rights reserved.
Error:
Error: File
Error: "C:\Users\myname\Documents\SVN\Test\bin\Debug\TestProject1.dll"
Error: not found .

So you can see I am calling MSTest correctly, but it's claiming the path is wrong.

BUT, if I open a VS Command Prompt manually and type the EXACT same path, the code runs without error.

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与君绝 2024-10-01 05:15:36

有可能,这实际上可能是权限问题,而不是 FnF 问题。

在执行代码时运行 filemon,并查看操作系统级别实际请求的内容。

It's possible, this may actually be a permissions issue, not a FnF issue.

Run filemon while you are executing the code, and see what is actually being requested at the OS level.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文