Question

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...

Was it helpful?

Solution

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>

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top