Reputation: 173
We have written a custom msbuild task that does some pre-processing of code files within our project. What we want to be able to do is to display the errors and warnings in the standard Error List window.
Visual Studio offers the TaskLoggingHelper (Log.LogError) method that is supposed to do this... but I have found that the Log.LogError(message, messageArgs) does not fill in the correct file name and line number... and the Log.LogError(subCategory, errorCode, helpKeyword, file, lineNumber, columnNumber, endLineNumber, endColumnNumber, message, messageArgs) returns with an error stating that message cannot be null even when I have explicitly set this.
It's seems that Visual Studio might not be using the overloaded (more detailed) method.
The code line I am sending is as follows..
string fileName = "main.c";
int lineNum = 415;
int colNum = 5;
string message = "Error Message Text.";
Log.LogError("", "", "", fileName, lineNum, colNum, 0, 0, message, null);
Has anyone successfully used this method overload to log an error in MSBuild??
Thanks
** UPDATE **
After reading Nick's response (below) I did the following test...
Log.LogError("test1", "test2", "test2", fileName, lineNum, colNum, 0, 0, message);
I removed the messageArgs and added some text to the first three parameters. The response I got was surprising... The message listed in the ErrorList window was "test1" and not "Error Message Text". Not sure this shines any light on situation though.
Dave
Upvotes: 3
Views: 2147
Reputation: 173
Okay after poking this problem for a LONG time.. I was never able to get the Log.LogError("", "", "", fileName, lineNum, colNum, 0, 0, message, null); solution to work. For whatever reason it appears that this overload is not implimented correctly. I ended up finding an alternate solution that does the same thing. I thought it would be good to supply my solution in case someone else wants to do the same;
BuildErrorEventArgs errorEvent = new BuildErrorEventArgs("", "", fileName, lineNum, colNum, 0, 0, messageErr, "", "");
BuildEngine.LogErrorEvent(errorEvent);
So what I did was to implement the IBuildEngine interface as part of my ITask class. From that I was able to access the LogErrorEvent which allows you to pass the BuildErrorEventArgs structure that gives you access to all the detail information for the error.
Hope this helps
Upvotes: 4
Reputation: 4458
If you've inherited from Microsoft.Build.Utilities.Task you should be able to use this for sure. I've been using it with the more simple overload syntax of :
base.Log.LogError(Strings.ItemsToFilterMissingError);
I noticed in the large overload you've specified the args to the message format string are of type
params object[] messageArgs
I think you can just omit the parameter instead of passing an explicit null. That may be your problem.
Upvotes: 0