Thursday, November 26, 2009

Display information in Visual Studio Error List

Problem:
I want to display information in Visual Studios Error List. So when I build my solution I'll get compilation issues and unit test information on the same place.

Solution:
Googled for a while and it turned out that this is actually pretty easy!
So now I have a this piece of code in my unit test framework:
public static string CreateErrorMessage(string message)
{
StringBuilder builder = new StringBuilder();
StackTrace trace = new StackTrace(true);
StackFrame frame = trace.GetFrame(3);

builder.Append(frame.GetFileName());
builder.Append("(");
builder.Append(frame.GetFileLineNumber());
builder.Append("): error MUNIT001: ");
builder.Append(message);

return builder.ToString();
}

No comments:

Post a Comment