visual-studio-2008 - 我可以从 Visual Studio 中的构建后事件调用的控制台应用程序发送错误吗?

标签 visual-studio-2008 build-process

因为我在 ASP.net Web 应用程序项目中设置了构建后事件以运行以下命令行。

启动 $(SolutionDir)[PathToMyApplicationInSameSolution] [一些参数]

所以我需要将一些错误从控制台应用程序发送到 Visual Studio 以显示构建错误(如 Visual Studio 构建错误)

谢谢


所以我将构建后事件命令更改为以下命令。

$(SolutionDir)[PathToMyApplicationInSameSolution] [一些参数]

然后,我编辑我的主要功能以显示错误。我在 Visual Studio 的错误列表中看不到任何内容。我只在输出中看到。您知道如何显示 Visual Studio 生成的构建错误之类的错误吗?

[STAThread]
static void Main(string[] args)
{
    Console.Error.WriteLine("Test Error");
    Console.WriteLine("test error");
}

谢谢

附言。因为我刚开始使用命令应用程序,所以我忘记了开始为控制台应用程序创建新线程。

最佳答案

您需要从您的应用程序返回一个错误结果。将 Main 的返回类型更改为 int。您不能使用“开始”,因为这会丢弃结果。

如果您想在错误列表窗口中显示错误消息,只需以正确的格式输出一个字符串...

using System;

namespace FailBuild
{
    static class Program
    {
        static int Main(string[] args)
        {
            string fileName =
                @"D:\Source\Roger\IsServiceStarted\IsServiceStarted.cpp";
            int lineNumber = 4;
            string errorCode = "X1234";
            string errorMessage = "I don't like the colour";

            Console.WriteLine("{0}({1}): error {2}: {3}",
                fileName, lineNumber, errorCode, errorMessage);
            return 1;
        }
    }
}

关于visual-studio-2008 - 我可以从 Visual Studio 中的构建后事件调用的控制台应用程序发送错误吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/781168/

相关文章:

c++ - Const 方法访问静态变量

c# - 有没有办法在 Visual Studio 2008 中使用 2005 C# 编译器?

asp.net - 如何避免从Visual Studio以 Debug模式发布ASP.NET应用程序?

asp.net - 使用 subversion 或 TFS,您将如何设置自动构建?

asp.net - 使用 Create-React-App,是否可以像使用 grunt/gulp 一样在构建过程中将代码注入(inject)/替换/附加到 index.html 文件中?

c++ - 我可以在不重新编译 exe 文件的情况下更改 dll 接口(interface)吗?

javascript - 用户控件中的 VS2008 javascript 调试器

azure - VSTS在线新建系统错误 "The specified path, file name, or both are too long."

visual-studio-2008 - 将 Qt 应用程序链接到 Google Breakpad 时出现 Unresolved 符号错误

makefile - 完美的makefile