返回MSBuild中CallTarget调用的目标的属性

时间:2011-04-12 17:20:36

标签: msbuild msbuild-propertygroup

我是msbuild的新手,但即使是google,我也不知道如何从MSBuild中的CallTarget返回一个属性(见下文)。这是不可能的还是

   <Target Name="CreateDbStgExistsProp">
   <!-- See http://stackoverflow.com/questions/1373162/passing-property-group-value-from-one-msbuild-task-to-another why this workaround is needed -->
   <PropertyGroup>
    <db>$(dbStg)</db>
    <machine>$(dwhdbStgmachine)</machine>
   </PropertyGroup>
  </Target>

  <Target Name="CheckDbStgExists" DependsOnTargets="CreateDbStgExistsProp">
   <CallTarget Targets="DBExists"/>
   <!-- this should pass the Property DoesDbExist for further reference created in Target DBExists, but it does not seem to work --> 
   <Message Text="Test: $(DoesDbExist)"/> 
  </Target>

  <Target Name="DBExists"   >
    <MSBuild.ExtensionPack.Sql2008.Database TaskAction="CheckExists" MachineName="$(machine)" DatabaseItem="$(db)" LogExceptionStack="true">
    <Output TaskParameter="Exists" PropertyName="DoesExist"/>
   </MSBuild.ExtensionPack.Sql2008.Database>
   <Message Text="Database $(db) does NOT exists" Condition="!$(DoesExist)"/>
   <Message Text="Database $(db) does exist" Condition="$(DoesExist)"/>
   <PropertyGroup>
     <DoesDbExist>$(DoesExist)</DoesDbExist>
   </PropertyGroup>

 </Target>  

1 个答案:

答案 0 :(得分:0)

改变这个:

<Target Name="CheckDbStgExists"
  DependsOnTargets="CreateDbStgExistsProp">
  <CallTarget Targets="DBExists" />

对此:

<Target Name="CheckDbStgExists"
  DependsOnTargets="CreateDbStgExistsProp;DBExists">

使用CallTarget执行目标时,所创建的任何动态属性都会以与DependsOnTargets运行时不同的方式“发布”。