Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild - can it work out project dependencies in a solution file? If so how?

Tags:

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?

like image 839
Dave Avatar asked Nov 13 '08 16:11

Dave


People also ask

How do you build specific targets in solutions using MSBuild EXE?

To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.

Is it possible to build an application on a system if the MSBuild is not installed?

Is it possible to build an application on a system if the MSBuild is not installed? If so, How? Yes, it is actually possible because the MSBuild doesn't depend on the Visual Studio of its operations. Users simply need to install the msbuild.exe file for this.


2 Answers

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.

like image 77
Scott Dorman Avatar answered Oct 16 '22 05:10

Scott Dorman


While Project Dependencies are hard to maintain and not shared across .sln files, Project References are honoured and do dictate the order consistently - see the ResolveReferences task in Microsoft.Common.targets.

ASIDE: A 'friend of mine' may 'during a refactoring' have accidentally stubbed out their Build Task and it's DependsOnTargets linkage to the Microsoft.Common.targets ResolveReferences task and ended up with ProjectReferences not being honoured in ways that sound like the question here. If you read some of the posts, you might get the idea that it's all mad shaky - it's not; the shaky bits are the Project dependencies, not the Project references.


See this excellent MSDN Blog article by Dan Moseley that really explains the topic, including some useful workaround strategies. (via this mildly related issue with building xUnit.net).

like image 30
Ruben Bartelink Avatar answered Oct 16 '22 06:10

Ruben Bartelink