How can I define properties dynamically and pass them to another target in msbuild?

.net, c#, msbuild, properties

Solution

There is a bug with dynamic items and properties:

The issue has to do with not being able to access items and properties that are created within a target until the target execution actually completes

(More info here).

The workaround is simple : use one separate target to create the property.

<Target Name="Release">
  <Message Text="Env: $(Env)"/>
</Target>

<Target Name="CreateProperty">
  <CreateProperty Value="Development">
    <Output TaskParameter="Value" PropertyName="Env" />
  </CreateProperty>      
</Target>

<Target Name="ReleaseIntegration" DependsOnTargets="CreateProperty">
  <Message Text="Env: $(Env)"/>
  <CallTarget Targets="Release"/>
</Target>

You will get:

Env: Development
Env: Development

Problem

I am trying to reuse a task in an Ant way: ``` <Target Name="Release"> <Message Text="Env: $(Env)"/> </Target> <Target Name="ReleaseIntegration"> <CreateProperty Value="Development"> <Output TaskParameter="Value" PropertyName="Env" /> </CreateProperty> <Message Text="Env: $(Env)"/> <CallTarget Targets="Release"/> </Target> ``` And I get: ``` Env: Development Env: ``` Any ideas how to get this property into Release target?

Original source