Can I send an error message from the console application that is raised by the post-build event in Visual Studio?

Since I set the post-build event in the ASP.NET Web Application project to run the following command line.

start $ (SolutionDir) [PathToMyApplicationInSameSolution] [some parameter]

Therefore, I need to send some error from the console application to Visual Studio to display the build error (for example, Visual Studio build error)

thanks


So, I change the post-build event command to the next command.

$ (SolutionDir) [PathToMyApplicationInSameSolution] [some parameter]

And then I edit the main function to display the error. I do not see anything in the error list in Visual Studio. I see only in Output. Do you know how to display an error such as a build error generated by Visual Studio?

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

thanks

Ps. Because I'm new to using the command-line application, so I forgot what to start, how to create a new thread for the console application.

+2
source share
3 answers

I found a solution to solve this problem. Visual studio will detect some output template that will display as an error. That way, I don't need to change the default main method interface to return int (but you can use the return value to identify the error publicly).

Additional Information: MSBuild / Visual Studio Error Messages and Message Formats

+2
source

You need to return the error result from your application. Change the return type of Main to int. You cannot use "start" because it will drop the result.

If you want an error message to be displayed in the error list window, just enter the string in the correct format ...

 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; } } } 
+1
source

If you do not use "start", the application output will appear in the Visual Studio output window.

0
source

Source: https://habr.com/ru/post/1392477/


All Articles