How do I keep values defined in one build target alive in other targert? If PropertyGroup is not the write MsBuild entity I should use here, what is? ReleaseDir is printed ok in "Package" target, but is empty in "DoPackage"
<Target Name="Package">
<PropertyGroup>
<ReleasesDir>c:\tmp</ReleasesDirBase>
</PropertyGroup>
<Message Text="$(ReleaseDir)"/>
<CallTarget Targets="DoPackage" Condition="!Exists('$(ReleaseDir)')"/>
</Target>
<!-- Do the acutal packaging -->
<Target Name="DoPackage">
<Message Text="Creating package in '$(ReleaseDir)'"/>
<Error Condition="'$(ReleaseDir)' == ''" Text="No ReleaseDir defined"/>
<MakeDir Directories="$(ReleaseDir)"/>
...
</Target>
If one wants to pass a property to a target, the MSBuild task can be useful. This is the only way to call a target multiple times with different property values, but it does not allow passing in items or item groups. See this comment in the thread that Julien links to.
Here is what your code snippet would look like using the MSBuild task:
This technique is useful if you want to use the target as a subroutine, which you can call multiple times with different parameter values. For example, to call a build process for several product configurations.
It might not be the cleanest way to solve this problem, but if some one still wants to use CallTarget on the build file, he/she must define the PropertyGroup in another Target, the following is the solution to this weird problem.
There is a well known issue with properties and the CallTarget task. You should use DependsOnTargets instead.