msbuildmsbuild-propertygroup

return properties from target called by CallTarget in MSBuild


I'm new to msbuild but even with google I don't have any idea how to return a property from a CallTarget in MSBuild (see below). Is that not possible or

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

Solution

  • Change this:

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

    To this:

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

    When a target is executed with CallTarget, any dynamic properties created are "published" in a different manner than if it is run because of DependsOnTargets.