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

I saw the answers to the same question, but not quite the same, but not with positive luck, to use the proposed solutions ... so I try 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 found that in these conditions it seems impossible to create two targets with the same name. One will deny the other. How can i do this?

+4
source share
1 answer

Provide a wrapper target that depends on both goals. Both will be called, but only one that matches the condition will really 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>
+7
source

All Articles