MSBuild Build Sequence

佐手、 提交于 2019-12-05 08:25:41

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>

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.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!