Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Build Sequence

Looking at this article from MS, I have a question about the SolutionToBuild section.

<ItemGroup>
    <SolutionToBuild Include="$(SolutionRoot)\path\MySolution.sln />
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\scribble.sln" />
    <SolutionToBuild Include="$(SolutionRoot)\HelloWorld\HelloWorld.sln" />
    <SolutionToBuild Include="$(SolutionRoot)\TestProject1\TestProject1.sln" />
</ItemGroup>

It says that the sequence of the build is determined by the order above. So, for example, MySolution would be built before scribble.

However, is this safe if scribble is dependant on MySolution? For example, MySolution outputs one or more dlls that are used by scribble. If MySolution and scribble are changed simultaneously, will the build wait for MySolution to be completely compiled before moving to the next project?

like image 721
Paul Michaels Avatar asked Jun 07 '10 17:06

Paul Michaels


2 Answers

You can try to use additional metadata for item SolutionToBuild. Some work with recursion and voilà!

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\levelone.sln">
        <DependsOnSolutions>$(SolutionRoot)\Scribble\leveltwo.sln</DependsOnSolutions>
    </SolutionToBuild>        
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\leveltwo.sln">
        <DependsOnSolutions>$(SolutionRoot)\Scribble\levelthree.sln;$(SolutionRoot)\TestProject1\TestProject1.sln</DependsOnSolutions>
    </SolutionToBuild>
    <SolutionToBuild Include="$(SolutionRoot)\Scribble\levelthree.sln" />
    <SolutionToBuild Include="$(SolutionRoot)\TestProject1\TestProject1.sln" />
</ItemGroup>

<Target Name="Build">
    <MSBuild Projects="$(MSBuildProjectFile)"
             Targets="BuildSolution"                 
             Properties="SolutionFullPath=%(SolutionToBuild.Identity)"/>
</Target>

<Target Name="BuildSolution">   
    <CreateItem Condition="'%(SolutionToBuild.Identity)'=='$(SolutionFullPath)'"
        Include="%(SolutionToBuild.DependsOnSolutions)">
        <Output TaskParameter="Include"
                ItemName="DependentSolutions" />
    </CreateItem>

    <Message Text="Building solution $(SolutionFullPath)..." />        
    <Message Text="Solution $(SolutionFullPath) depends on %(DependentSolutions.Identity)..." 
             Condition="'@(DependentSolutions)'!=''"/>
    <Message Text="Building dependent solutions..."
             Condition="'@(DependentSolutions)'!=''"/>

    <MSBuild Projects="$(MSBuildProjectFile)"
             Targets="BuildSolution"
             Properties="SolutionFullPath=%(DependentSolutions.Identity)"
             Condition="'@(DependentSolutions)'!=''"/>

    <!-- <MSBuild Projects="$(SolutionFullPath)" /> -->
    <Message Text="Building solution $(SolutionFullPath)... OK" />
</Target>
</Project>
like image 132
Sergio Rykov Avatar answered Oct 02 '22 14:10

Sergio Rykov


How do you manage solution dependency? Aren't you referencing projects instead? I'm also puzzled about the 'simultaneous' changes on some of your solutions. Please clarify the nature of these changes.

So far, the answers to your questions are:

  1. No. They may be compiled one after the other, but does it qualify for dependency?
  2. Yes. If the sequence is mandatory, the builder will 'wait' until each solution is built (either with success or error) before moving to the next.
like image 36
Humberto Avatar answered Oct 02 '22 14:10

Humberto