Jonathan Allen
Jonathan Allen

Reputation: 70337

How do I envoke a MSBuild target in the middle of another target?

What I'm looking for is something like:

<Target Name="DoStuff" >
    <Message Text="Doing stuff..." />
    //run target DoOtherThing
    <Message Text="Doing more stuff..." />
</Target>

Upvotes: 0

Views: 48

Answers (1)

stijn
stijn

Reputation: 35911

There's CallTarget which you'd use like

<Target Name="DoStuff" >
  <Message Text="Doing stuff..." />
  <CallTarget Targets="DoOtherThing" />
  <Message Text="Doing more stuff..." />
</Target>

and there's the more idiomatic, albeit a bit over the top for this case, way:

<ItemGroup>
  <MyTargets Include="Message1" />
  <MyTargets Include="DoOtherThing" />
  <MyTargets Include="Message2" />
</ItemGroup>

<Target Name="Message1" />
  <Message Text="Doing stuff..." />
</Target>

<Target Name="DoOtherThing" />
  <CallTarget Targets="DoOtherThing" />
</Target>

<Target Name="Message2" />
  <Message Text="Doing more stuff..." />
</Target>

<Target Name="DoStuff" DependsOnTargets="@(MyTargets)">
</Target>

Upvotes: 1

Related Questions