MSBuild conditionals depending on task parameters
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 SubSystem
parameter roughly like this:
<PropertyGroup Conditional="'$(Link/SubSystem)'=='Console'" />
but don't know if it is possible, and if it is, what the correct s开发者_Go百科yntax is.
I'm pretty new to MSBuild though, so it's perfectly possible that I've missed something.
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>
...
精彩评论