Custom targets are skipped after first run in TFS build
I have a custom target (group of copy tasks, among others) in my assembly that I need to call a couple of times to make changes in different places. However, this is only done the first time it is called, after which the TFS collection skips the specified target.
The process is carried out as follows:
<!-- Copy some files to another location --> <CallTarget Targets="CopyFiles"></CallTarget> ... <!-- Copy the above files to yet another location --> <CallTarget Targets="CopyFiles"></CallTarget>
The build log shows that the target instance "CopyFiles" is skipped the second time it is called:
Target "CopyLicenseManagerFiles" skipped. Previously built successfully.
Why is this happening? Is there a way to make the target (or whatever custom target post I write) run multiple times?
source to share
It must be called once per MSBuild instance, for each set of parameters. In some cases Team Build will allocate separate instances of MSBuild (for example, if you provide more than one solution configuration). But that probably won't help you.
More specifically for your scenario, MSBuild will rerun the task if you call it with a different set of parameters. If you are copying two different sets of files that sounds like the feature you are looking for.
<MSBuild Project=".\CommonStuff.targets" Targets="CopyFiles" Properties="Location=1" /> <!-- .... --> <MSBuild Project=".\CommonStuff.targets" Targets="CopyFiles" Properties="Location=2" />
Another solution is to refactor the functionality into an Objective instead of an Objective. While declarative and procedural quirks still exist, Tasks behave much closer to what you would think of as a "function" from more familiar languages.
source to share