MSBuild performance within an iterator

I need to compile all the .Net 2.0 C# projects within a particular directory. I’ve authored a file iterator to retrieve all the .csproj files into a file set. I then loop through that set executing an MSBuild action for each of the .csproj files.

This directory contains several hundred, small .Net 2.0 projects. The FinalBuilder process with the MSBuild action takes about 45 minutes. If I execute a batch file containing all the MSBuild statements for each of the .csproj files, it takes about 10 minutes.

I’m assuming the time difference is due to constantly invoking MSBuild. Is there a better approach? Should I execute my MSBuild “master” (containing references to all the individual .csproj files) in one swoop?

This approach would perform better but I like the maintainability of the loop/iteratation approach. I intend to add FxCop, NUnit, WIX, etc. items into the loop as I progress.

Is there a better approach? (project structure screen cap attached)


fb-project.gif

Posted By Jeff Hunsaker on 14 Dec 2006 4:24 PM
I need to compile all the .Net 2.0 C# projects within a particular directory. I've authored a file iterator to retrieve all the .csproj files into a file set. I then loop through that set executing an MSBuild action for each of the .csproj files.

This directory contains several hundred, small .Net 2.0 projects. The FinalBuilder process with the MSBuild action takes about 45 minutes. If I execute a batch file containing all the MSBuild statements for each of the .csproj files, it takes about 10 minutes.

I'm assuming the time difference is due to constantly invoking MSBuild. Is there a better approach? Should I execute my MSBuild "master" (containing references to all the individual .csproj files) in one swoop?

This approach would perform better but I like the maintainability of the loop/iteratation approach. I intend to add FxCop, NUnit, WIX, etc. items into the loop as I progress.

Is there a better approach? (project structure screen cap attached)



Hi Jeff

You are right that the speed issue is due to the msbuild engine being invoked multiple times. A better solution would be to have Finalbuilder generate a master msbuild project file with the files from the fileset. I would create a template project file, and then use the fileset, iterator and xml actions to generate the msbuild project.

HTH

This one got my interest piqued, so I decided to see if I could come up with an example.

I’ve attached an example FB5 project and template msbuild project file. The way it works is this :

Define a Fileset with .csproj files
Define an XML Document using the template.proj file as the source.
Iterate the FileSet
For each file add an MSBuild Node to the Target node
Call MSBuild.

On my machine it’s an order of magnitude faster than calling msbuild on each project individually. There are probably more tweaks that can be done to specify configurations etc.

HTH



masterproject.zip (3.194 KB)

This was a rock star solution. It retained most of my performance while remaining “dynamic” in discovery of project files. Appreciate the starter code and the assistance.

I’d like to share the solution but there doesn’t appear to be an easy way to accomplish this. Maybe FB 6.x could export scripts to XML…? :wink:

Jeff,

I am not quite getting you here? Do you want to write out the msbuild solution or the FB project?

You could just write a text file and save it as xml. Or if you want the FB project as xml just store the file as fbp.

HTH

Ah, didn’t know that was possible. Thanks.