Ask a questionAsk a question
 

AnswerForce a target to rebuild?

  • Thursday, October 13, 2005 4:34 PMTaylor Brown Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have a target that I would like to run twice during my build.  Once, before I do any work, I want to clean up some files in a directory.  Then, later on in the build, after I've created some files, I want to do the same cleanup on the same directory using the exact same algorithm.  Is there a way to call my target again and force it to run? The only thing I could think of doing was using the Exec task to run MSBuild.  CallTarget and MSBuild both remember what targets have already run, so that won't work.

    Dependency checking is awesome...except when you don't want it.

    Many thanks,

       Taylor

Answers

  • Thursday, October 13, 2005 5:09 PMFaisal Mohamood MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Having a target run once and only once was an explicit design decision, as it is almost universally required in the world of build.

    Now that said, there are cases where you do need to run a target more than once during the same build session.  You can do this by using a trick.  It involves using the MSBuild task to call the target.

    If you want MSBuild to invoke the target multiple times during the build, pass in a different set of properties each time into the MSBuild task you use to invoke the target, and the target will execute as you want it.

    Faisal Mohamood

All Replies

  • Thursday, October 13, 2005 5:09 PMFaisal Mohamood MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Having a target run once and only once was an explicit design decision, as it is almost universally required in the world of build.

    Now that said, there are cases where you do need to run a target more than once during the same build session.  You can do this by using a trick.  It involves using the MSBuild task to call the target.

    If you want MSBuild to invoke the target multiple times during the build, pass in a different set of properties each time into the MSBuild task you use to invoke the target, and the target will execute as you want it.

    Faisal Mohamood

  • Thursday, October 13, 2005 6:17 PMTaylor Brown Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I see!  Thanks for the reply.  I presume that requires that I declare that property as an input? Off to test now...

       - Taylor
  • Thursday, October 13, 2005 6:40 PMTaylor Brown Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Awesome - I see now that as long as you supply a different property value to any property, including a property made up on the spot, the target gets rebuilt.  Woo hoo!  Thanks for the tip!

    Now I can just do this:

     <MSBuild
       Projects="$(MSBuildProjectFile)" 
       Targets="CleanUnnecessaryPatches"
       Properties="Rerun=true;">
      </MSBuild>

       - Taylor