A reader of this blog asked me to review some reusable MSBuild file that he created. I won't reveal the details of his files here but here are my comments which are relevant to all reusable MSBuild files.

Properties in targets files

For targets file (MSBuild files designed to be imported by other files) if possible you should always define properties using conditions to ensure that the consumer hasn't alredy defined that value. See my new article MSBuild Best Practices (http://msdn.microsoft.com/en-us/magazine/dd419659.aspx) specifically the section titled "Defining Dynamic Items and Properties".

Assumptions in targets files

Your ProjectOutputHelper.targets file overrides the BuildDependsOn property. This is good and I am sure that it works great, but I don't agree 100% with this approach. You are assuming that the consumers of the file will be importing the Microsoft.Common.targets file which is most likely true, but in my opinion is a bad practice. Better would be to allow consumers of the file to extend the BuildDependsOn. See my new book Inside the Microsoft Build Engine in Chapter 7 you will find a section ‘Creating Reusable Build Elements’ which define some rules for targets files, this is explained more there.

Extendable targets should declare dependencies in a property

All non-internal targets contained inside of targets files should declare the target dependencies inside of a property. This allows consumers to inject steps into specific areas of the build process. For instance from Microsoft.Common.targets:

<PropertyGroup>

    <BuildDependsOn>

        BeforeBuild;

        CoreBuild;

        AfterBuild

    BuildDependsOn>

PropertyGroup>

<Target

    Name="Build"

    Condition=" '$(_InvalidConfigurationWarning)' != 'true' "

    DependsOnTargets="$(BuildDependsOn)"

    Outputs="$(TargetPath)"/>

Design incremental targets

If possible you should design your targets to build incrementally ( Chapter 6 of my book explains this) so that the targets that are already up-to-date don’t have to be rebuilt. It is good to get into the habit of creating targets that build incrementally.

Use MSBuild 3.5 Syntax

If you are building with MSBuild 3.5 (.NET 3.5) you should use the new ItemGroup and PropertyGroup elements inside of the targets instead of the CreateProperty and CreateItem task.


Comment Section

Comments are closed.


Microsoft Press Blog Posting

Comments [1]
The The Microsoft Press team has posted a blog about my book & upcoming articles, you can read it at All Sayed all the time (and MSBuild). These guys make it seem like I'm actually doing something, when in reality I've been on vacation for the past 5 weeks!

Sayed Ibrahim Hashimi


Comment Section

Comments are closed.


I will be speaking on MSBuild at the South Florida .NET Code Camp on Saturday Feb 7. If you are in the area and interested in MSBuild then come and check me out!

Sayed Ibrahim Hashimi


Comment Section

Comments are closed.


My new book Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build has been published and is now in stock at amazon.com. This book contains 12 chapters, 9 of which are dedicated to MSBuild and the remaining three are Team Build. Two of the MSBuild chapters are dedicated to examples in a cook book fashion, there is one such chapter for the Team Build. This book is the only book that contains this type of coverage of MSBuild. From the begining of the book the MSBuild team was involved, they reviewed every MSBuild chapter and provided invaluable insight. Here is the table of contents for the book:
Chapter 1 : MSBuild Quick Start
Chapter 2 : MSBuild Deep Dive, Part 1
Chapter 3 : MSBuild Deep Dive, Part 2
Chapter 4 : Custom Tasks
Chapter 5 : Custom Loggers
Chapter 6 : Batching and Incremental Builds
Chapter 7 : External Tools
Chapter 8 : Practical Applications, Part 1
Chapter 9 : Practical Applications, Part 2
Chapter 10 : Team Build Quick Start
Chapter 11 : Team Build Deep Dive
Chapter 12 : Team Build Cookbook
App A : New Features in M Build 3.5
App B : MSBuild Common Properties and Items
App C : New Features in Visual Studio Team System 2010 Team Build

If you are interested in learning MSBuild from scratch, or looking to become a MSBuild expert then this book will help you. If you do get a copy please post a review on amazon.com.

Sayed Ibrahim Hashimi

Comment Section

Comments are closed.


This past weekend I gave a presentation on MSBuild at the Tampa Code Camp, which I'm glad to say went very well. Besides that I met Brian Johnson from Microsoft. He shot a video of me discussion using MSBuild and Web Deployment Projects to automate deployment of Web Projects. You can see the video at http://channel9.msdn.com/posts/brianjo/Sayed-Hashimi-on-MS-Build/

Let me know what you think, I'm pretty excited because this is my first Channel 9 video.

The sample demonstrated here was inspired by some content that can be found in my new book Inside the Microsoft Build Engine. The book will be published the beginning of January, please buy several copies! I will post more detailed information about the book soon, but we have completed working on it.


Sayed Ibrahim Hashimi


Comment Section

Comments are closed.


<< Older Posts | Newer Posts >>