none
Build Proj Solution Order

    Domanda

  • Hi,

    I have an MSBuild .proj file, that lists a number of solutions to be built. When running in serial, this works fine, but I'd like to use the /m switch to speed up the build of the application.

    The application consists of several solutions, each containing many projects. Whilst each solution has the dependencies defined between the projects in that solution, it is unaware of the dependencies of previous solutions.

    Ideally, I would like to control this from in the proj file, without making any changes to the solutions themselves.

    So basically, What I want to do is for each project in the solution to build in parallel (where possible, based on their own dependencies), but each solution to execute in serial.

    Is this possible at all?

    Thanks

    Fergal

    martedì 28 febbraio 2012 16:41

Risposte

  • Hi Obsidain,

    Yes, it is possiable. I believe you list all the solutions in your proj file and use "MSBuild" Task to build the solutions.  If it is, we can use BuildInParallel property to set if the MSBuild task builds the proejcts in Parallel. In addition, to make the solutions builds serially, list the msbuild task one by one for each single solutions. The following is a sample:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Target Name ="Build">
        <MSBuild BuildInParallel="true" Projects="Solution1.sln" />
        <MSBuild BuildInParallel="true" Projects="Solution2.sln" />
        <MSBuild BuildInParallel="true" Projects="Solution3.sln" />
    
      </Target>
    
     </Project>

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    • Contrassegnato come risposta ObsidianPhoenix mercoledì 29 febbraio 2012 10:18
    mercoledì 29 febbraio 2012 02:55
  • Hi,

    Two things need to be notice.

    1. You don't need to add /m toMSBuild command line, which will make all your solution build in parallel.

    2. You'd better NOT use Itemgroup to define the solution list to build. Consider you are using BuildinParallel property, it will make MSBuild task believe all your input solutions are required build in parallel.

    Generally speaking, MSbuild will execut the task one by one. Please refer to my above sample, I define couple msbuild tasks to build a set of solutions one by one, and each task will build all projects in the solution in parallel.

    Hope it help you.

    Regards,

    Yi   


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    • Contrassegnato come risposta ObsidianPhoenix mercoledì 29 febbraio 2012 10:18
    mercoledì 29 febbraio 2012 09:38

Tutte le risposte

  • Hi Obsidain,

    Yes, it is possiable. I believe you list all the solutions in your proj file and use "MSBuild" Task to build the solutions.  If it is, we can use BuildInParallel property to set if the MSBuild task builds the proejcts in Parallel. In addition, to make the solutions builds serially, list the msbuild task one by one for each single solutions. The following is a sample:

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <Target Name ="Build">
        <MSBuild BuildInParallel="true" Projects="Solution1.sln" />
        <MSBuild BuildInParallel="true" Projects="Solution2.sln" />
        <MSBuild BuildInParallel="true" Projects="Solution3.sln" />
    
      </Target>
    
     </Project>

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    • Contrassegnato come risposta ObsidianPhoenix mercoledì 29 febbraio 2012 10:18
    mercoledì 29 febbraio 2012 02:55
  • Thanks Yi (或是,你叫"FengLi"?)

    The structure we have in place in the file is as below. I don't really know how to the structure works, but simply adding BuildinParallel to the MSBuild Task didnt seem to work. Should I be doing something different?

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <Project DefaultTargets="LocalBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <Configuration>Debug</Configuration>
        <Targets>CleanProjects;BuildProjects</Targets>
        <StopOnFirstFailure>false</StopOnFirstFailure>
      </PropertyGroup>
    
      <ItemGroup>
        <ProjectsToBuild Include="Solution1.sln" />
        <ProjectsToBuild Include="Solution2.sln" />  
    </ItemGroup>
    
      <Target Name="LocalBuild" DependsOnTargets="$(Targets)" />
    
      <Target Name="BuildProjects">
        <MSBuild Projects="@(ProjectsToBuild)" StopOnFirstFailure="true" BuildinParallel="true" Properties="Configuration=$(Configuration);" />
      </Target>
    
      <Target Name="CleanProjects">
        <MSBuild Projects="@(ProjectsToBuild)" Targets="Clean" Properties="Configuration=$(Configuration);" />
      </Target>
    
      <Target Name="PrintProjects">
        <Message Text="Project Files:%0d%0a@(ProjectsToBuild,'%0d%0a')" Importance="high" />
      </Target>
    </Project>

    Thanks

    Fergal

    mercoledì 29 febbraio 2012 08:33
  • Oh no, I realised that I needed to still add the /m to the MSBuild arguments.

    However, It's still coming back with a heap of errors due to some of the files not being built in the correct order.

    mercoledì 29 febbraio 2012 08:53
  • Hi,

    Two things need to be notice.

    1. You don't need to add /m toMSBuild command line, which will make all your solution build in parallel.

    2. You'd better NOT use Itemgroup to define the solution list to build. Consider you are using BuildinParallel property, it will make MSBuild task believe all your input solutions are required build in parallel.

    Generally speaking, MSbuild will execut the task one by one. Please refer to my above sample, I define couple msbuild tasks to build a set of solutions one by one, and each task will build all projects in the solution in parallel.

    Hope it help you.

    Regards,

    Yi   


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    • Contrassegnato come risposta ObsidianPhoenix mercoledì 29 febbraio 2012 10:18
    mercoledì 29 febbraio 2012 09:38
  • Ah ok. I see now.

    It seemed to work better that time, although I didnt see any improvement in performance it seems. The entire build takes 3.5 minutes if I use the Item Group and don't include the BuildInParallel flag. It took the same time using the syntax you specified above, so perhaps there just isnt any performance gain to be had in this situation. Unless I am missing something:

    <?xml version="1.0" encoding="utf-8" standalone="yes"?>
    <Project DefaultTargets="LocalBuild" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
        <Configuration>Debug</Configuration>
        <Targets>CleanProjects;BuildProjects</Targets>
        <StopOnFirstFailure>false</StopOnFirstFailure>
      </PropertyGroup>
    
      <ItemGroup>
        <ProjectsToBuild Include="Solution1.sln" />
        <ProjectsToBuild Include="Solution2.sln" />      
        <ProjectsToBuild Include="Solution3.sln" />
    	...
    </ItemGroup>
    
      <Target Name="LocalBuild" DependsOnTargets="$(Targets)" />
    
      <Target Name="BuildProjects">
    	<MSBuild Projects="Solution1.sln" BuildInParallel="true" StopOnFirstFailure="true" Properties="Configuration=$(Configuration);" />
        <MSBuild Projects="Solution2.sln" BuildInParallel="true" StopOnFirstFailure="true" Properties="Configuration=$(Configuration);" />
        <MSBuild Projects="Solution3.sln" BuildInParallel="true" StopOnFirstFailure="true" Properties="Configuration=$(Configuration);" />
    	...
    	</Target>
    
      <Target Name="CleanProjects">
        <MSBuild Projects="@(ProjectsToBuild)" Targets="Clean" Properties="Configuration=$(Configuration);" />
      </Target>
    
      <Target Name="PrintProjects">
        <Message Text="Project Files:%0d%0a@(ProjectsToBuild,'%0d%0a')" Importance="high" />
      </Target>
    </Project>

    (NB: I've left the item group in place for the Clean operation, but am not using it during the build operations.)

    mercoledì 29 febbraio 2012 09:53
  • Hi,

    As you requested, "What I want to do is for each project in the solution to build in parallel (where possible, based on their own dependencies), but each solution to execute in serial." The performance really depends on how the projects in a solution. Suppose the projects in a solution are under strong dependency, the BuildInParallel will not make any performance improvement.

    If I misunderstand you, please let me know.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us

    mercoledì 29 febbraio 2012 10:07
  • No, it looks like you have the jist of it. Oh well, it looks like I will just have to leave it as is.

    Thanks for your help

    Fergal

    mercoledì 29 febbraio 2012 10:17