Search code examples
msbuildmsbuild-target

How do you control build order of sibling dependent targets with msbuild?


In my project, I have two import statements:

<Import Project="<TransformConfigLocation>" />
<Import Project="<PackageLocation>" />

Each target has a property group defined like so:

<PropertyGroup>
    <BuildDependsOn>
        $(BuildDependsOn);
        TransformConfig
    </BuildDependsOn>
</PropertyGroup>

<PropertyGroup>
    <BuildDependsOn>
        $(BuildDependsOn);
        Package
    </BuildDependsOn>
</PropertyGroup>

I would like to guarantee that TransformConfig always runs before Package. I do not control either of the dependent targets and would prefer not to have to edit them explicitly because those edits would be wiped any time I updated those targets via NuGet. The Package target consistently runs first which is undesirable.

Is this possible?


Solution

  • The simple answer is that the order of the Imports does matter. For more detail on why, see @Seva Titov's answer and our follow up conversation.

    I highly recommend http://amzn.com/0735645248 for a thorough analysis on the topic.