Monday, February 02, 2009
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

Monday, February 02, 2009 4:17:35 AM (GMT Standard Time, UTC+00:00)  #    Comments [1]  | 
Friday, January 30, 2009

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

Friday, January 30, 2009 8:10:43 PM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Saturday, January 17, 2009
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
Saturday, January 17, 2009 4:05:26 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Tuesday, December 09, 2008

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

Tuesday, December 09, 2008 5:09:44 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Friday, December 05, 2008

I am not sure why but for some reason I always manage to post these messages at the last minute, sorry for that. I will be speaking at the Tampa Code Camp on Saturday December 6. We will cover various features of MSBuild. If you are in the area, and interested in MSBuild, please come check out my presentation.

 

Sayed Ibrahim Hashimi

Friday, December 05, 2008 5:35:58 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Monday, November 10, 2008

Out of the box Team Build does not support Delta Builds. Thomas Janssen has a detailed post Realizing Delta Builds with VSTS Team Build for Delta Deployments which describes how this can be achieved. I have not had the opportunity to try this myself, but the blog post looks very through and informative. You can also download his DeltaBuild.targets file from his blog. I have the following comments relating to this; perhaps he will upgrade this file to reflect these comments.

This guidance is appropriate for target files which are designed to be consumed by others.

Don't override targets like AfterCompileSolution

Don't override targets like AfterCompileSolution. Instead extend the CompileSolutionDependsOn property in the manner:

<PropertyGroup>

<CompileSolutionDependsOn>

$(CompileSolutionDependsOn);

DeltaAfterCompileSolution

</CompileSolutionDependsOn>

</PropertyGroup>

This is because some consumers of this file may have already defined the AfterCompileSolution target. In which case one of them will be overridden.

Notice that I named the new target DeltaAfterCompileSolution. It is a best practice to prefix your targets with a value that should be unique. This will minimize the chances of your targets colliding with those defined by others. For example this could have been named MyAfterCompileSolution, but I bet there are a bunch of these already defined.

DependsOnTargets should always be taken from a property

You should define the DependsOnTargets value inside of a property, just like the MSFT targets files do. For example your DeltaAfterCompileSolution (after being renamed) would look like this:

<PropertyGroup>

<DeltaAfterCompileSolution>

$(DeltaAfterCompileSolution);

SafeCleanBuildResult;

GetLatestVersion;

CollectIncrementalBuildResult;

CreateDeltaBuildResult

</DeltaAfterCompileSolution>

</PropertyGroup>

<Target Name="DeltaAfterCompileSolution"

DependsOnTargets="$(DeltaAfterCompileSolution)">

</Target>

This is because you want users to be able to extend this process similar to how users extend the built-in build process. Without this they may need to modify your file, which is ill-advised because you may make a new release at some point.
Also notice the usage of the $(DeltaAfterCompileSolution) in the declaration of the DeltaAfterCompileSolution property. This is to
preserve any previous values that the user may have defined.

 

On a side note, if you are looking for more detailed information regarding Team Build, there will be three chapters of my new book Inside the Microsoft® Build Engine: Mastering MSBuild and Team Build which will be published in January 2009. Sample chapters will be available at that link shortly.

Thanks,

Sayed Ibrahim Hashimi

Monday, November 10, 2008 4:43:46 AM (GMT Standard Time, UTC+00:00)  #    Comments [0]  | 
Friday, October 10, 2008

I will be speaking at the Tallahassee Code Camp on Saturday 11, 2008. I will be presenting MSBuild there. I think I should have posted this blog earlier but I've been too busy writing my new book!

Sayed Ibrahim Hashimi

Friday, October 10, 2008 5:06:42 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]  | 
Monday, September 08, 2008

I was looking at the documentation for the Exec task (yes I'm writing a new MSBuild book!) and discovered that it is lacking. So I decided to post the complete list of properties here. So here it is for those of you using it.

Name

Description 

Command 

The command which is to be executed. This is the only required parameter.

CustomErrorRegularExpression *

If provided this will be the regex used to determine if an error occurred.

CustomWarningRegularExpression *

If provided this will be the regex used to determine that a warning occurred.

ExitCode

Output property containing the exit code provided by the executed command.

IgnoreExitCode

If true then the Exec task will not fail the build based on the exit code. Otherwise the build is failed for any non-zero exit code.

IgnoreStandardErrorWarningFormat *

If true the output is not examined for errors and warnings.

Outputs

An input/output parameter that contains the output items from the task. This is not set by the Exec task itself but made available to be set by the consumer.

StdErrEncoding

An input/output parameter that specifies the encoding that is used for the standard error stream.

StdOutEncoding

An input/output parameter that specifies the encoding that is used for the standard output stream.

Timeout

Specifies the timout, in milliseconds for the command. After the specified amount of time has passed the command will be terminated. By default there is no timeout

ToolPath

Specifies the location of the tool.

WorkingDirectory 

Specifies the working directory.

* Denotes new properties in MSBuild 3.5

There is a slightly new behavior in this version of the task relating to detecting errors & warnings from the output of the command. Take a look at the forum entry Exec task and "error :" in output.

More to come on the new book later keep an eye here soon. If you have ideas about specific examples that should be demonstrated let me know, for example; how to zip a set of file, how to ftp files to a server, your example here, etc.

Sayed Ibrahim Hashimi

Monday, September 08, 2008 5:23:19 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]  | 
Wednesday, July 30, 2008

I looked around for an extension method that would just randomize a list. I found a couple but they either didn't seem to work right or the modified the collection itself instead of creating a new collection and returning that. So I created one, it is pretty simple anywayz. The definition for it is shown below.

public static class IListExtensions
{
    public static IList<T> Randomize<T>(this IList<T> input)
    {
        if (input == null)
        { throw new ArgumentException("input"); }

        var test = (from p in input
                    select new { Id = rand.Next(), ListObject = p }).OrderBy(t => t.Id);

        IList<T> randomList = new List<T>();
        foreach (var item in test)
        {
            randomList.Add(item.ListObject);
        }

        return randomList;
    }

    static Random rand = new Random();
}

From here we use this method just like any other IList method, an example is shown below.

public void SampleRandomize()
{
    int numElemnets = 10;
    IList<int> numList = new List<int>();
    for (int i = 0; i < numElemnets; i++)
    {
        numList.Add(i);
    }

    IList<int> radnomList = numList.Randomize();

    for (int i = 0; i < randomList.Count; i++)
    {
        System.Diagnostics.Debug.WriteLine(string.Format("i: {0}", randomList[i]));
    }
}

I think it's pretty cool how you can create methods that can be soo easily used thanks to extension methods.


Sayed Ibrahim Hashimi

Wednesday, July 30, 2008 6:31:15 AM (GMT Daylight Time, UTC+01:00)  #    Comments [0]  | 
Friday, June 27, 2008

This post is related to my  previous post MSBuild RE: Enforcing the Build Agent in a Team Build which is a response on the post by Michael Ruminer at http://manicprogrammer.com/cs/blogs/michaelruminer/archive/2008/06/19/enforcing-the-build-agent-in-a-team-build.aspx.

Basically every MSBuild element can contain a Condtions attribute. You can read more at MSBuild Conditions. So even targets can have conditions attached to them! Despite the fact that you can do this, you should not. I recommend that you do not use conditions on targets. Conditions on targets seem straight forward but after you take a closer look they are more complicated. We can take a look at some of the items that come to mind here.

Conditions on targets and DependsOnTargets don’t play well

Take a look at this simple project file

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="2.0"
         xmlns="
http://schemas.microsoft.com/developer/msbuild/2003"
         DefaultTargets="Demo">

  <PropertyGroup>
    <AllowTarget>true</AllowTarget>
  </PropertyGroup>

  <Target Name="SupressTarget">
    <CreateProperty Value="false">
      <Output PropertyName="AllowTarget" TaskParameter="Value"/>
    </CreateProperty>
    <Message Text=" ==== SupressTarget ==== " Importance="high"/>
    <Message Text="AllowTarget: $(AllowTarget)"/>
  </Target>
 
 
  <Target Name="Demo" Condition="'$(AllowTarget)'=='true'"
          DependsOnTargets="SupressTarget">
    <Message Text=" ===== Demo ===== " Importance="high" />

    <Message Text="AllowTarget: $(AllowTarget)"/>
  </Target>
 
</Project>

In this project the main target is Demo and it depends on a target SupressTarget which actually disables the Demo target based on its condition. If you execute the command msbuild /t:Demo you get the results shown below.

Most users would expect that the target SupressTarget target would execute which sets the AllowTarget value to false, and then the Demo target is skipped. But what is happening here is that by the time DependsOnTargets is evaluated the condition has already been evaluated and has passed! The even more interesting thing here is if you execute msbuild /t:SupressTarget;Demo the results are shown below.

 

So this time it was skipped, because SupressTarget was called before the Demo target was invoked so the condition evaluated to false.

 

Conditions and target batching doesn’t work well either

If you are batching a target and you want to execute the target for some batches but not others, this cannot be achieved with target conditions, for a few reasons but the simplest is: Either a target is or is not defined. When the target is going to be executed for the first time the condition is evaluated. If the condition is true it will exist, otherwise it will not.

I thought of some other issues but they are not coming to me at this time, but I think this is enough to deter you from using target dependencies. Instead of target dependencies you should take a look at other way of achieving the same results.

 

Sayed Ibrahim Hashimi

Friday, June 27, 2008 7:28:35 AM (GMT Daylight Time, UTC+01:00)  #    Comments [2]  | 

Theme design by Jelle Druyts