0

I have a build task that I am working on using msbuild. Within the task I have several targets, some of which perform preparation work.

When I execute "msbuild myEvent.msbuild /t:event3" the event runs. The first event in the DependsOnTargets executes but the second event in the list of targets does not. Example

<!-- only event1 will fire -->
<Target Name="event3" DependsOnTargets="event1; event2">
   <Task TaskAction="myAction3"/>
</Target>
<Target Name="event1" DependsOnTargets="event4">
   ... do tasks here
</Target>
<Target Name="event2" >
   ... do tasks here
</Target>
<Target Name="event4" >
</Target>

I have attempted to modify this by eliminating the space in the DependsOnTargets values. I ensure that I have semicolon separated values. I have tried using BeforeTargets and AfterTargets without success.

My msbuild code targets ToolsVersion 4.0.

Is there something that I am missing with how DependsOnTargets works?

EDIT

  • I think I figured out my problem. MSBuild does not allow me to execute the same target more than once.
  • In this case I have to do the following
    • start a database service
    • drop databases
    • stop the service
    • Extract some database files from a zip file
    • start the database service
    • Attach databases
    • Perform further action on databases ...
  • The first start database service will execute as well as drop databases and stopping the service. The next call to start the database service fails.
Daniel Lee
  • 674
  • 1
  • 9
  • 25
  • After thinking through this some more I think I know the problem. The problem is that in my sequence of events, I call one of the events multiple times. Since the event already ran once, the event does not get called again. In my case I have to start a service, perform an action, stop a service, perform another action while service is stopped, and then start the service again to perform another action. :) – Daniel Lee Oct 24 '16 at 15:59
  • I am trying to utilize a target like a task in order to reduce repeated code. A target will execute once and only once it appears. – Daniel Lee Oct 24 '16 at 18:33
  • Yes, a target never runs twice during a single build, even if a subsequent target in the build depends on it. Once a target runs, its contribution to the build is complete. Since your original issue has been solved, you can post an answer and mark it after 24 hours. – starian chen-MSFT Oct 25 '16 at 03:27

1 Answers1

0

The problem was because I was treating a target like a task; I was trying to reduce duplicate code.

Once a target executes, it never executes again. So the takeaway here is to be clear what is a target and what is a task.

I currently have this resolved by removing the targets that are intended to be tasks and create the required tasks, such as starting and stopping services, within the correct targets.

Daniel Lee
  • 674
  • 1
  • 9
  • 25