tags:

views:

131

answers:

1

In MSBuild it's straightforward to define, say, a PropertyGroup which depends on the value of a property Foo:

<PropertyGroup Conditional="'$(Foo)'=='Bar'" />

Is it also possible for the conditional to depend on a task parameter?

For example, I'd like to use the value of the Link task's SubSystemparameter roughly like this:

<PropertyGroup Conditional="'$(Link/SubSystem)'=='Console'" />

but don't know if it is possible, and if it is, what the correct syntax is.

I'm pretty new to MSBuild though, so it's perfectly possible that I've missed something.

A: 

I don't have the VC SDK on my machine here, so I can't try a Link Task but you could try using the <Output /> of the Task:

...
<PropertyGroup Condition="'$(LinkSubSystem)'=='Console'">
    <MyDependentProp>Whatever</MyDependentProp>
</PropertyGroup>

<Target Name="Linker">
    <Link Sources="@(LinkerSources)" SubSystem="Console">
        <Output TaskParameter="SubSystem" ItemName="LinkSubSystem" />
    </Link>
</Target>
...

A second approach could be to use a property for Link Task SubSystem param itself an just recycle it for your PropertyGroup.

...
<PropertyGroup>
    <LinkerSubSystem>Console</LinkerSubSystem>
</PropertyGroup>

<PropertyGroup Condition="'$(LinkerSubSystem)'=='Console'">
    <MyDependentProp>Whatever</MyDependentProp>
</PropertyGroup>

<Target Name="Linker">
    <Link Sources="@(LinkerSources)" SubSystem="$(LinkerSubSystem)" />
</Target>
...
Filburt