在目标中设置的MSBuild属性在父目标中不可见

时间:2015-08-03 08:28:03

标签: msbuild msbuild-task msbuild-propertygroup

这是我的目标文件

<?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>

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

在目标&#34; TestInit&#34;中设置的TestInitResult的值在目标&#34; BuildApp&#34;中不可见当它返回时。

请告诉我如何在父目标中显示TestInitResult。 或者是否有更好的方法来实现所需的结果。

我想要实现的是,首先应该运行TestInit目标,然后运行target2,并且只有在TestInit成功时才应运行目标RunBuild。如果TestInit失败,只运行target2,跳过RunBuild。

谢谢。

0 个答案:

没有答案