here is my targets file
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="BuildApp" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="12.0">
<PropertyGroup>
<TestInitResult>false</TestInitResult>
</PropertyGroup>
<Target Name="BuildApp">
<CallTarget Targets="TestInit" ContinueOnError="true"/>
<Message Importance="high" Text="2 Value of flag: $(TestInitResult)"/>
<CallTarget Targets="target2" />
<CallTarget Targets="RunBuild" Condition="'$(TestInitResult)'=='true'"/>
</Target>
<Target Name="TestInit">
<PropertyGroup>
<TestInitResult>true</TestInitResult>
</PropertyGroup>
<Message Importance="high" Text="1 Value of flag: $(TestInitResult)"/>
</Target>
<Target Name="target2">
<Message Importance="high" Text="Inside run target2"/>
</Target>
<Target Name="RunBuild">
<Message Importance="high" Text="Inside run build"/>
</Target>
</Project>
Output of msbuild:
D:\CQF>msbuild build.targets
Microsoft (R) Build Engine version 12.0.30501.0
[Microsoft .NET Framework, version 4.0.30319.34209]
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 7/31/2015 4:38:49 AM.
Project "D:\CQF\build.targets" on node 1 (default targets).
TestInit:
1 Value of flag: true
BuildApp:
2 Value of flag: false
target2:
Inside run target2
Done Building Project "D:\CQF\build.targets" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.06
The value of TestInitResult set in target "TestInit" is not visible in target "BuildApp" when it returns.
Please let me know how to make TestInitResult visible in parent target. Or is there better approach to achieve the required result.
What I want to achieve is, first TestInit target should run, then target2 should run, and target RunBuild should run only if TestInit was successful. If TestInit failed, only run target2, skip RunBuild.
Thank you.