-1

Is it possible to return an array, list or object out of a custom logger?

I want to add all errors and warnings generated by MSBuild and store them in an array, then pass this array back to my build script and report on it if necessary.

Is this possible?

  • Might be possible, but what have you tried so far? SO isn't a 'please give me the code' site so as it stands your question is going to be closed soon. Writing a custom logger is relatively easy and there are code samples all over here, so just try it first and then if you hit an actual problem come back here with some code and stating the exact problem. – stijn Apr 08 '16 at 06:52
  • Hi stijn, thanks for your comment. I'm not looking for any code. I asked, is it possible. I've been looking around at many examples and haven't seen one where something is returned from the custom logger on build complete. – David Power Apr 08 '16 at 08:08

1 Answers1

0

You cannot do this directly: a logger is passed to the build engine when it's contructed, like on the commandline, and there doesn't seem to be a way to access it afterwards from within an msbuild script. Programmatically, maybe, but again I wouldn't know how to do that. Moreover a logger adheres to the ILogger interface and that's all msbuild sees, so whatever methods you add won't be accessible anyway.

There are workarounds though: see this for example. The trick is that the dll containing your custom logger can be accessed from within msbuild, so if you have a logger collecting events and storing them in a static List in the dll that same list can be accessed using a custom task in the same dll. Make that task return the static List to the msbuild script again as an ItemGroup and you're good to go.

Community
  • 1
  • 1
stijn
  • 34,664
  • 13
  • 111
  • 163