BT

Custom MSBuild Tasks

| by Hartmut Wilms Follow 0 Followers on Feb 21, 2008. Estimated reading time: 1 minute |

Since version 2.0 Microsoft has integrated MSBuild, a build system, into the .NET Framework that is fully compatible with Visual Studio projects. Bart de Smet shows how to extend MSBuild via custom tasks.

Although the set of built-in MSBuild tasks covers most of a developer's needs, some areas - especially deployment, integration of version control systems, configuration of servers and IIS web sites as well as ActiveDirectory tasks are left out. The MSBuild Community Tasks Project and the SDC Tasks Library, which are both freely available, provide many MSBuild tasks that address most of the issues in these areas. If something's still missing, you have to (and can) help yourself.

Bart de Smet shows how to create and debug custom MSBuild tasks. Whereas his first article serves as an introduction to creating custom tasks, his second article is written in a cookbook-style and focuses on debugging. According to Bart the development of a custom task is divided into 8 steps:

Step 1 - Create a Class Library project

Step 2 - Import references

Step 3 - Implement the task skeleton

Step 4 - Task parameterization

Step 5 - Implementing functionality

Step 6 - Setting up debugging

Step 7 - Set a breakpoint and run

Step 8 - Advanced debugging

Debugging is essentially configured in the custom MSBuild task's project properties: The project's start action must be set to the MSBuild executable (which should match the MSBuild assemblies referenced by the project) and the start options have to include the path to a test MSBuild project file.

The MSBuild Team blog provides further information and help, and the article "MSBuild - What It Does and What You Can Expect in the Future" by Dan Moseley and Xin Yan is a good summary of MSBuild's features, concepts, new file format features in .NET 3.5, and future directions.

Rate this Article

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Unit Tests ??? by Pawel Stasiak

Seems that somebody forgot to add appropriate steps for unit tests preparation and execution...

MSBuild as xm script by Alvaro Gareppe

The MSBuild Custom Tags are very useful not only to especial deployment needs... are also useful to develop complex scripts where each step could be a custom task defined by the developer i.e. I have developed task to verify table data in automatic tests.

You could use msbuilds and custom tags to develop specific scripts, where each action is develop by yourself, and the script flow is defined by the msbuild xml.

Some information about msbuild for Spanish-speaking: allyoucaneatin30.blogspot.com/2008/02/msbuild-t...

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

2 Discuss
BT