PostBuild events not running on TFS Team Build

I have been struggling today with a problem that a PostBuild event on a C# project works fine on my development PC but failed on a Team Build box. The project is based on the Codeplex  SharePoint Visual Studio Project Template that uses post build scripts to create a deployment WSP.

It turns out the problem was an unwanted condition on the PostBuildEvent in the projects .csproj file. It was like this:

<PropertyGroup>
    <PostBuildEvent Condition=" '$(TeamBuildConstants)'=='' ">
          echo POSTBUILD STARTED
    </PostBuildEvent>
</PropertyGroup>

when it should have been

<PropertyGroup>
    <PostBuildEvent>
          echo POSTBUILD STARTED
    </PostBuildEvent>
</PropertyGroup>

Where this condition came from I am not sure, as if I create a new project of this type from the sample template it was not there. As this was an existing project I guess it got edited in at some point in the past, why I can’t think. Anyway it is awkward to spot if you don’t look at the .csproj file in notepad.