Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Msbuild now to conditionally use one of two targets with same name

I've seen some answers to a similar question but not exactly the same and not with positive luck trying to use suggested solutions... so I'm trying something like this:

<project>
    <target name="foo" Condition="'$(Configuration)' == 'Debug' ">
        <Message Text="=== RUNNING FOO DEBUG TARGET ===" />
    </target>
    <target name="foo" Condition="'$(Configuration)' == 'Release' ">
        <Message Text="=== RUNNING FOO RELEASE TARGET ===" />
    </target>
</project>

... but I'm finding that it doesn't appear to be possible to have two targets with the same name working properly under these conditions. One will negate the other.

How can I do this?

like image 491
Maniaque Avatar asked Jun 18 '15 00:06

Maniaque


1 Answers

Provide a wrapper target, that depends on both targets. The both will be called, but only the one matching the condition will actually do something.

<Project>
    <Target Name="foo" DependsOnTargets="_fooDebug;_fooRelease"/>

    <Target Name="_fooDebug" Condition="'$(Configuration)' == 'Debug' ">
        <Message Text="=== RUNNING FOO DEBUG TARGET ===" />
    </Target>
    <Target Name="_fooRelease" Condition="'$(Configuration)' == 'Release' ">
        <Message Text="=== RUNNING FOO RELEASE TARGET ===" />
    </Target>
</Project>
like image 106
Christian.K Avatar answered Nov 02 '22 11:11

Christian.K