Search code examples
c#msbuild-taskxml-validation

Throwing Custom Compiler Warnings when writing custom Msbuildtask


I am using msbuildtask to validate an xml file on Build. I am able to do that using the Execute method after extending Task. Am not able to display Custom Warnings or messages stating the reason for build fail. Is there any custom way to throw compiler warning from code?


Solution

  • I found that using ITask interface gives us some additional power of interaction with Msbuild engine than Task interface.

    • Implement ITask interface for a class and add Code to perform ur task in Execute Method of it.
    • Add this task in the csproj.
    • When implementing ITask interface there is a way to contact the compiler and pass it Messages or Warnings or Errors. Here is a basic example of a class which implements ITask interface http://blogs.msdn.com/b/msbuild/archive/2006/01/21/515834.aspx