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

前端 未结 7 880
北海茫月
北海茫月 2021-02-01 05:24

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 m

7条回答
  •  猫巷女王i
    2021-02-01 06:04

    There is no Microsoft tool that will examine all the dependencies of your 70+ projects and generate a solution file with dependencies clearly declared for you.

    You have to do that on your own by using 2 different methods:

    1. Manually specify a dependency, for the solution, in visual studio.
    2. Specify a project reference in the project file itself.

    If you don't want to do that, then you will have to swallow the medicine and accept that you will to use an external tool to do that for you. Yes it's clunky but it can be made to work. If you check in your solution file to your source control you can mitigate these problems. As long as you have an active solution file to work with.

    I at one point didn't, and I had 600+ projects in the build. So I wrote a tool (years ago) that would automate 99% of this work. It uses the .NET MSBuild API's to read the msbuild files (no recreating the wheel here with xml api's). It then examines outputs and inputs and generate a dependency tree which I can then do a few things with it:

    1. Spit out a solution file.
    2. Do a dependency sort (also a topological sort in academia), and spit out those projects in order they should be built (for a non-parallel type of build, which can be useful sometimes).
    3. print out all sorts of diagnostic information about dependencies.

    The only limitation I have seen with the tool is with a few crazy COM dependencies which are pretty sketchy anyways. Which I added a super simple work-around.

提交回复
热议问题