0

I need to tie together a bunch of steps which include building solutions, projects and running .cmd files using a custom MSBuild file.

My first pass at this is below:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
      <Configuration>Release</Configuration>
      <Platform>AnyCPU</Platform>
   </PropertyGroup>
   <ItemGroup>
      <ProjectsToBuild Include="..\Hosts\solution1.sln"></ProjectsToBuild>
      <ProjectsToBuild Include="..\..\solution2.sln"></ProjectsToBuild>
      <ProjectsToBuild Include="helper1.csproj"></ProjectsToBuild>
      <ProjectsToBuild Include="..\..\Sandboxes\helper2.sln"></ProjectsToBuild>
      <Exec Include="" Command="CALL GetFiles.cmd"/>
      <ProjectsToBuild Include="wix\proc\prod.wixproj"></ProjectsToBuild>
      <Exec Command="CALL final.cmd"/>
   </ItemGroup>
   <Target Name="Build">
      <MSBuild Projects="@(ProjectsToBuild)" Targets="Build">
        <Output ItemName="ProjectOutputs" TaskParameter="TargetOutputs"/>
    </MSBuild>
    <Message Text="@ProjectOutputs"/>
   </Target>       
</Project>

This resulted in an error since the Exec element is in the wrong place.

Basically, I need to build solution1.sln, solution2.sln,helper1.csproj and helper2.sln (in sequence), then, run the file GetFiles.cmd, then build prod.wixproj followed by running the final.cmd file.

I have looked at MSDN (here, here, here), a blog, and browsed through various stackoverflow questions (including this, this, this, this), but none of them quite address what I am trying to do. This is the first time I have ever worked with MSBuild, so it is possible I may have missed something. Will appreciate any pointers...

Community
  • 1
  • 1
Manas
  • 521
  • 8
  • 26
  • You can use targets to control the sequence in which you build the solutions. http://msdn.microsoft.com/en-us/library/vstudio/ee216359.aspx – Nicodemeus May 14 '13 at 01:18
  • @NickCarlson Thanks. But how do I link ItemGroup to Target? – Manas May 14 '13 at 01:36
  • ItemGroup can also be a child node of Target. Each target could have it's own item group it is responsible for. You could specify the build order at the level, or through the various *Targets attributes on the level. (below) – Nicodemeus May 14 '13 at 01:38

2 Answers2

2

Since an ItemGroup node can be a child of a Target node, break down those ItemGroup members into separate targets, then use the DefaultTargets attribute to control the sequence in which those are built.

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Target1;Target2;Target3" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5" >
    <Target Name="Target1">
        <Message Text="Target 1" />
    </Target>
    <Target Name="Target2">
        <Message Text="Target 2" />
    </Target>
    <Target Name="Target3">
        <Message Text="Target 3" />
    </Target>
</Project>
Nicodemeus
  • 4,005
  • 20
  • 23
1

The build projects are already in the correct order see:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>AnyCPU</Platform>
  </PropertyGroup>
  <ItemGroup>
    <ProjectsToBuild Include="..\Hosts\solution1.sln"></ProjectsToBuild>
    <ProjectsToBuild Include="..\..\solution2.sln"></ProjectsToBuild>
    <ProjectsToBuild Include="helper1.csproj"></ProjectsToBuild>
    <ProjectsToBuild Include="..\..\Sandboxes\helper2.sln"></ProjectsToBuild>
    <ProjectsToBuild Include="wix\proc\prod.wixproj"></ProjectsToBuild>

  </ItemGroup>
  <Target Name="Build">
    <Exec Command="CALL GetFiles.cmd"/>
    <Message Text="Build order: %(ProjectsToBuild.Identity)"/>

    <MSBuild Projects="@(ProjectsToBuild)" Targets="Build">
      <Output ItemName="ProjectOutputs" TaskParameter="TargetOutputs"/>
    </MSBuild>
     <Message Text="@(ProjectOutputs)"/>

    <<Exec Command="CALL final.cmd"/>
  </Target>
</Project>

At the start the order of the itemgroup is displayed:

Project "C:\Test\Testcode\build\testcode.msbuild" on node 1 (default targets).

Build:

Build order: ..\Hosts\solution1.sln

Build order: ....\solution2.sln

Build order: helper1.csproj

Build order: ....\Sandboxes\helper2.sln

Build order: wix\proc\prod.wixproj

All done.

James Woolfenden
  • 6,498
  • 33
  • 53
  • I need to run GetFiles.cmd between building helper2.sln and prod.wixproj. Please correct me if I am wrong, but it doesn't look like that will be the case in your answer. – Manas May 14 '13 at 16:10
  • If thats the case then you need to split the itemgroup and call the msbuild target using each itemgroup. – James Woolfenden May 14 '13 at 16:16