How to determine if a target will be executed?

Posted by Scott Langham on Stack Overflow See other posts from Stack Overflow or by Scott Langham
Published on 2010-03-11T10:26:47Z Indexed on 2010/03/14 19:45 UTC
Read the original article Hit count: 167

Filed under:

Hi, I'm writing an msbuild file and have something like this:

<ValidateDependsOn>$(ValidateDependsOn);ValidateA</ValidateDependsOn>
<ValidateDependsOn>$(ValidateDependsOn);ValidateB</ValidateDependsOn>

<Target Name="BuildA">
    <!-- stuff -->
</Target>

<Target Name="BuildB">
    <!-- stuff -->
</Target>

<Target Name="ValidateA">
    <Error /> <!-- check properties and machine environment are suitable to run BuildA -->
</Target>

<Target Name="ValidateB">
    <Error /> <!-- check properties and machine environment are suitable to run BuildB -->
</Target>

Builds can take a while. Originally we had the Build steps depending on the Validate steps, but sometimes a validate step wouldn't run until the middle of the build and you would have wasted time getting there. So, we moved the validate steps to the start by using the ValidateDependsOn pattern to insert the targets to run up front.

The problem now though is that sometimes during a build BuildB may not actually run, and this means I don't need and in fact, don't want ValidateB to run. Is there any way I can selectively update ValidateDependsOn by conditionally knowing which targets will actually be run?

I'm looking for something equivalent to:

<ValidateDependsOn Condition="TargetWillRun(BuildB)">$(ValidateDependsOn);ValidateB</ValidateDependsOn>

© Stack Overflow or respective owner

Related posts about msbuild