views:

3593

answers:

6

Hi,

I have an msbuild project which builds a SLN file from visual studio which holds all the projects in (about 70+ project), and a lot of the projects are dependent on each other meaning they need to be build in order - sometimes a developer forgets to set the build order manually in visual studio in the solution file causing the msbuild on a clean solution to fail as something gets built out of order/cant find a dll.

Is there a way for msbuild to take all projects and work out the dependencies and build the projects in order, if there is how do i do this? using an MSBuild task? With current tries it seems to just build in the order it reads the projects in - if i pass in a list of project files+paths.

Currently the only way i can think to solve this is a external app which scans the proj files and references and then manually creates a solution each time.. but this seems overkill for such a simple thing.

Anyone solved / seen this before?

Cheers

A: 

check out http://stackoverflow.com/questions/272199/why-am-i-missing-assemblies-from-the-bin-directory-when-compiling-with-msbuild

Bruno Shine
I don't see anywhere on that page that discusses working out project dependencies...
Mattias Andersson
A: 

If all of your dependent projects are in the solution and you are using Project references, Visual Studio should manage the dependencies for your and build in order of that dependency list.

It sounds like you are not using project references. I always recommend project references.

Mr. Kraus
+2  A: 

How are you calling MSBuild? If you point MSBuild to the solution file, it should be able to work out the dependencies. If you point it to individual project files, then it won't be able to resolve any project references.

If you don't use project references you can still control the dependency order in a solution by using the "Project Dependencies" dialog to manually set the dependencies.

Scott Dorman
A: 

While it is correct that MSBuild should observe the build order when you use project dependencies there is one caveat. It doesn't at present observe the reverse build order when building the clean target (as I have blogged about here). For regular build however it works nicely as described by others here.

+1  A: 

This is an old question but the issue was most likely that projects in the solution used direct references to dependent DLLs (Add Reference > select Browse tab > select dependent DLL) instead of using project references (Add Reference > select Projects tab > select dependent project). With direct references, Visual Studio can't figure out the dependency chain. You must tell it by right clicking on the solution node and select Properties. Pick Common Properties > Project Dependencies to set the required projects. Mr. Klaus is correct but I wanted to document how to fix this issue.

Sixto Saez
A: 

Is this your problem? It's currently giving me trouble.

http://social.msdn.microsoft.com/Forums/en/msbuild/thread/80cc6447-b720-4806-8395-7c257b207613?prof=required

There doesn't seem to be a great solution. I think we're going to write a tool to parse through the .sln file, look in the referenced .csproj files for the tags, and copy that info back into the .sln file.

Scott Langham