Search code examples
visual-studiomsbuildmsbuild-target

Run msbuild task with an external condition


Is it possible to ignore a target in a proj file? Anything of the sort of

msbuild amazingproject.proj /IgnoreTarget:TimeConsumingTarget

or can we set a condition value for the target while calling msbuild?

msbuild amazingproject.proj /Variable:TimeConsumingCondition=False

& in the proj file we can have

<targed name="TimeConsumingTarget" Condition="$(Variable:TimeConsumingCondition)"=="True">

Any other suggestion that works?

The whole story: We have many developers, some of whom need this target to run and some don't. So we need a conditional call for the target.


Solution

  • Just look at the documentation of Target.

    Project:

    <Target Name="TimeConsumingTarget"
            Condition="'$(BuildTimeConsumingTarget)'=='True'">
    

    Invoked like:

    msbuild amazingproject.proj /p:BuildTimeConsumingTarget=false