Visual studio 2008 我可以从VisualStudio中生成后事件调用的控制台应用程序发送错误吗?

Visual studio 2008 我可以从VisualStudio中生成后事件调用的控制台应用程序发送错误吗?,visual-studio-2008,build-process,Visual Studio 2008,Build Process,因为我将ASP.net Web应用程序项目中的后期生成事件设置为运行以下命令行 start$(SolutionDir)[pathtomyaapplicationnsasemosolution][some参数] 所以我需要将一些错误从控制台应用程序发送到VisualStudio,以显示生成错误(如VisualStudio生成错误) 谢谢 因此,我将post-build-event命令更改为以下命令 $(SolutionDir)[PathTomyApplicationsAsMesolution][

因为我将ASP.net Web应用程序项目中的后期生成事件设置为运行以下命令行

start$(SolutionDir)[pathtomyaapplicationnsasemosolution][some参数]

所以我需要将一些错误从控制台应用程序发送到VisualStudio,以显示生成错误(如VisualStudio生成错误)

谢谢


因此,我将post-build-event命令更改为以下命令

$(SolutionDir)[PathTomyApplicationsAsMesolution][某些参数]

然后,我编辑我的主函数以显示错误。我在Visual Studio中的错误列表中看不到任何内容。我只看到输出。您知道如何显示VisualStudio生成的错误(如生成错误)吗

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


另外,因为我不熟悉使用命令应用程序,所以我忘记了像为控制台应用程序创建新线程这样的启动。

如果不使用“启动”,应用程序的输出将显示在Visual Studio的输出窗口中。

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

如果要在错误列表窗口中显示错误消息,只需以正确格式输出字符串

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;
        }
    }
}

我找到了解决这个问题的办法。VisualStudio将检测要报告为错误的某些输出模式。所以,我不需要将默认的主方法接口更改为返回int(但可以使用返回值公开标识错误)


更多信息:

关于StackOverflow,请在答案中添加注释,而不是创建另一个答案。另外:如果希望停止构建,则应返回非零结果。