How to call a custom target after building each individual solution (sln) in Team Build?


Issue: –

I would like to invoke a specific target just after each solution is compiled. Unfortunately, team build performs a build including all solution in an atomic MSBuild call. I don’t want to make changes in my sln or csproj files but I am OK with modifying the tfsbuild.proj. What can I do to get the desired behavior?



This is possible in Team Build but is slightly complicated. You need to override the default CoreCompile target with your own version.

To give you the idea of what needs to be done, please refer this simplified script –

In this proj file, all the three projects (classlibrary1, classlibrary2, classlibrary3) are build for each configuration (Debug|AnyCPU, Release|AnyCPU) and the target CommonPostCompileStep is invoked after project is build for a particular configuration.  


<?xml version=1.0 encoding=utf-8?>

<Project xmlns=>




    <!– List of projects to build –>

    <SolutionToBuild Include=.\ClassLibrary1\ClassLibrary1.sln />

    <SolutionToBuild Include=.\ClassLibrary2\ClassLibrary2.sln />

    <SolutionToBuild Include=.\ClassLibrary2\ClassLibrary2.sln /> 





    <!– Configuration to build –>

    <ConfigurationToBuild Include=Release|Any CPU>


      <PlatformToBuild>Any CPU</PlatformToBuild>



    <ConfigurationToBuild Include=Debug|Any CPU>


      <PlatformToBuild>Any CPU</PlatformToBuild>





  <Target Name=CoreCompile>


    <!– Call the compile for each configuration –>




            Properties=Platform=%(ConfigurationToBuild.PlatformToBuild);Flavor=%(ConfigurationToBuild.FlavorToBuild); />




  <Target Name=RunCoreCompileWithConfiguration>


    <!– Call the compile for each project (per configuration), with your custom target –>



            Targets=RunCoreCompileForProject; CommonPostCompileStep



ProjectToBuild=%(SolutionToBuild.Identity) />




  <Target Name=RunCoreCompileForProject>


    <!– Actual compile for a particular {configuration, project} pair –>






          Targets=ReBuild />



  <Target Name=CommonPostCompileStep>


    <!– Custom target to execute after building each project/solution–>

    <Message Text=Common postcompile target to execute after building solution/>







Note the following issues when making changes in your tfsbuild.proj file


  1. In msbuild task, Projects property – use $(SolutionRoot)\TeamBuildTypes\$(BuildType)\tfsbuild.proj instead of using $(MSBuildProjectFile). Otherwise the teambuild logger will crash

  2. As you are spanning msbuild process for each project (per configuration) separately, this will have performance implication.

  3. If making change in your csproj file to include custom post build step is easier. However if you are building large number of solutions and making changes in individual files is painful then this might be an better approach.

Please feel free to use this example as hint and customize your CoreCompile target.




Comments (8)

  1. Manish Agarwal tells us how to call a custom target after building each individual solution in Team Build….

  2. Jan Bergstrom says:

    I have tried to do something like this on the main Microsoft.TeamFoundation.Build.targets file on CoreCompile.  I would like to insert a target that is executed for each configuration immediately before that configuration.

    If I use $(SolutionRoot)TeamBuildTypes$(BuildType)tfsbuild.proj as the reference for the recursive call to the project file, it can’t find my solutions (because it now searches relative to this file rather than relative to $(SolutionRoot)..BuildTypetfsbuild.proj.  If I use $(SolutionRoot)..BuildTypetfsbuild.proj, the build crashes on the server claiming that it can’t find the working directory.

    How do I insert a target into the CoreBuild step that is executed once for each configuration, and not mess up all the other stuff that the Microsoft.TeamFoundation.Build.targets CoreBuild is doing?

  3. Jan Bergstrom says:

    I think I have answered my own question:

    When calling the target for MSBuild to do the CoreCompile, pass the original $(SolutionRoot) with


  4. Steven St Jean says:

    At the end of your article, you mention that the logger will crash under certain circumstances.  Can you elaborate further on why this occurs?  I am using your pattern to perform code generation prior to compilation and it looks like the logger is crashing during the run.  My build is failing and I have a truncated build log.

  5. Steven St Jean says:

    Your override of the CoreCompile target does fewer tasks than the original version in Microsoft.TeamFoundation.Build.targets.  Do you believe that this will materially change the behavior of the overridden build vs. the behavior of the original?

  6. Buck Hodges says:

    For those who try this, note that you’ll need to copy the TeamBuildMessage task invocations as well, otherwise the logger will crash (Steve points this out in his blog post  The v1 logger depends on those messages to determine what’s being built.

    Regardless, it’s not a good idea to override any of the Core* targets, especially CoreCompile, as they will definitely be changing in future releases.


  7. Buck Hodges says:

    There have been several times when folks have needed to run a custom target prior to building each solution…