简体   繁体   中英

Detect and Build Dependencies for C# Solutions

We have a Project with a number of different solutions files and each solution then has many projects. The problem is that there are projects that need to be built for certain solutions. Each developer has to go through the pain of opening a large solution (a solution that contains many projects). The problem is that these solutions don't always build because a certain build order has to be followed.

My question is, is there a way to identify dependencies for each project in a given directory and then build these projects. Something like find all the project files that don't have any dependencies on our other projects that we own. So build such projects first then build the ones whose dependencies are already built.

I was thinking of using F# or Fake to do this but I am not sure where to start or if it is even possible.

I would really appreciate an answer with an example or links to where I can get help.

Regards,

Nasir

If you want to go with something off the shelf. Resharper from JetBrains has a very nice tool for viewing project build dependencies. This will help you create a build script with the correct build order.

http://www.jetbrains.com/resharper/webhelp/Architecture__Project_Dependencies_Exploration.html

Implementing the analysis in F# yourself wouldn't be too complicated.

For example, you can do it in 2 phases:
1. Go through your solution folder structure and build a map of (project file name -> full path of file).
2. Go through all the files you found, and for each file add references to other solutions projects to a graph structure.

Then you build progressively projects that don't have any (yet unbuilt) references.

Project files are easy to parse, being XML. Solution projects can be recognised by the relative path reference:

<ProjectReference Include="..\MyProjFolder\MyProjFile.csproj">
<!--                      --^                              -->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM