MSBuild equivalent of Nant Solution task ...
With Nant I can do the following:
<solution configuration="debug" outputdir="${build.dir}">
<projects>
<includesList name="${Includes.List.Name}" />
</projects>
</solution>
Where includes.list.name is a text file list of .csproj files in my application.
The nant solution tasks will build all the projects in correct order - most dependent projects first, etc.
The app is fairly large >450 projects and growing.
Is there an equivalent in msbuild?
Have you tried to use the MSBuild task? You simply need to specify the name of the solution in the Project attribute - as shown.
<Target Name="BuildMySolution">
<MSBuild Projects="My.sln" />
</Target>
Faisal Mohamood
MSBuild Team
Thanks for the response.
I don't think that creating a single solution with 450 projects and figuring out all the dependencies is practical.
My project is part of an automated nightlybuild with the developers adding new projects several times a week. With Nant, the projects are just added to the existing project file list (text file) and the solution task figures out the dependencies from all the .csproj files.
Works well but I want to switch to msbuild.
You can still use the MSBuild task to use a list of items as the projects to build. Have you tried something along these lines?
<Project DefaultTargets="BuildSolution" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Project Include="ClassLibrary2\ClassLibrary2.csproj"></Project>
<Project Include="ClassLibrary1\ClassLibrary1.csproj"></Project>
</ItemGroup>
<Target Name="BuildSolution">
<MSBuild Projects="@(Project)"></MSBuild>
</Target>
</Project>
Faisal Mohamood
MSBuild Team
Doesn't work because it won't build projects in "dependency order' - meaning the most dependent project first. In your example, if ClassLibrary2 uses ClassLibrary1, ClassLibrary1 needs to be built before ClassLibrary2.
For your example build file, ClassLibrary2 is built first but can't find the referenced ClassLibrary2 (assuming a clean build).
I built some test projects based on one of the MSBuild samples where there are 4 projects, Alpha, Beta, Gamma and Delta.
Beta references Alpha and Delta. Gamma references Alpha.
If I create a solution, and add the dependencies in manually the build order is:
Alpha, Delta, Beta and Gamma.
This build file fails:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Project Include="Alpha\Alpha.csproj" />
<Project Include="Beta\Beta.csproj" />
<Project Include="Gamma\Gamma.csproj" />
<Project Include="Delta\Delta.csproj" />
</ItemGroup>
<Target Name="BuildAll">
<MSBuild Projects="@(Project)" />
</Target>
</Project>
while this one will work
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Project Include="Alpha\Alpha.csproj" />
<Project Include="Delta\Delta.csproj" />
<Project Include="Beta\Beta.csproj" />
<Project Include="Gamma\Gamma.csproj" />
</ItemGroup>
<Target Name="BuildAll">
<MSBuild Projects="@(Project)" />
</Target>
</Project>
For my project I would like to do
<ItemGroup>
<Project Include="**\*.csproj" />
</ItemGroup>
The Nant Solution task figures out the dependency and builds in the correct order. I could probably build a custom msbuild task to do a similar thing or a tool to create my master.proj with the files in the correct order.
Aha - I forgot to mention one important detail. You are absolutely right in the sense that it will not work as you have it now.
It works with VS style Project2Project references. So in my projects, I had references between projects set up like the following. You should be able to create a dummy project out of VS that references another project within the solution and this is how it will be referenced.
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj">
<Project>{FFA5DDFD-0632-4A75-AE77-D34EF4DA2924}</Project>
<Name>ClassLibrary1</Name>
</ProjectReference>
</ItemGroup>
But you are absolutely right in the sense that a custom task could be written to do what you mentioned as well! Which approach do you think you will take?
Faisal Mohamood
MSBuild Team
I think that I am getting ahead of myself on this. Our consultant tells me that this won't be a problem for us since we are going to use Team System and Team Build.
We also aren't going to have .csproj files for some of our projects; namely webservices and webforms projects.
I created the current build system but when we go to .NET 2.0 and Whidbey things are going to be different.
I realize that I have a lot to learn - which is good.
I appreciate your help with my struggles.