开发者

MSBuild conditionals depending on task parameters

开发者 https://www.devze.com 2022-12-26 21:21 出处:网络
In MSBuild it\'s straightforward to define, say, a PropertyGroup which depends on the value of a property Foo:

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

精彩评论

暂无评论...
验证码 换一张
取 消