Debugging a MSBuild Task using Visual Studio

Off lately, MSBuild Tasks are becoming more and more popular. One obvious reason is that things can be implemented real fast. For instance, if one needs to check the existence of a directory in a project in a solution, and then take some action based on its existence, there is no need to write a 100 line to first use the EnvDTE80 ‘s DTE2 interface to get the project and then find directory and take action. The same can be done using MSBuild Task quite easily.

Debugging MSBuild Tasks seems tricky. Here is how to debug a custom tasak:-

  1. Create a test project to debug your task in.
  2. Edit the *.csproj/*.vsproj to add in the necessary MSBuild XML to make use of the task.
  3. Close the test project.
  4. Open the custom task project.
  5. Right click on the project and select “Properties”.
  6. In the new window that opens, click on the “Debug” tab.
  7. Change the start action to “Start External Program” and put the full path to MSBuild as the name of the program.
  8. In the arguments text box, enter the full path to the test project (created above).
  9. Save and close the property window.

Now it is possible to put a breakpoint on the Execute() method of the custom task and debug.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s